[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [Orgmode] Automatic screenshot insertion

From: François Pinard
Subject: Re: [O] [Orgmode] Automatic screenshot insertion
Date: Wed, 04 Jan 2012 23:54:06 -0500
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/23.3 (gnu/linux)

Russell Adams <address@hidden> writes:
> On Sun, Nov 28, 2010 at 08:35:23PM +0100, David Maus wrote:
>> At Thu, 18 Nov 2010 18:16:22 +0100, Jonathan BISSON wrote:

>> > Here is a little function that allows a user to insert a screenshot
>> > easily. Only works on unix-like systems where ImageMagick is installed
>> > (adapt "import" to your screenshot program if needed).

>> Nice.  Do you mind of I put the function on Org mode'S wiki (Worg) in
>> the "Org hacks" page?[1]

> I made a minor change. File names are now generated by using the
> current org buffer filename, plus the date and time, and a unique
> number. This allows me to sort out the images better.

For my own usage, I modified it further, like below:

(defun fp-org-image (name)
  "Insert a link to an already existing image, or else to a screenshot.
The screenshot is either taken to the given non-existing file name,
or added into the given directory, defaulting to the current one."
  ;; FIXME: Should limit to '("pdf" "jpeg" "jpg" "png" "ps" "eps")
  ;; which is org-export-latex-inline-image-extensions.
  (interactive "GImage name? ")
  (when (file-directory-p name)
    (setq name (concat
                 (concat (file-name-as-directory name)
                          "." "-"
                          (file-name-sans-extension (buffer-file-name)))))
  (unless (file-exists-p name)
    (unless (file-writable-p name)
      (error "Cannot create image file"))
    (message "Taking screenshot...")
    (call-process "import" nil nil nil name)
    (message "Taking screenshot...done"))
  (insert (concat "[[" name "]]"))

The changes are:

* LaTeX processing fails if there is more than one period, because
  everything after the first period is considered as the extension,
  which is not recognized as a graphic one.

* Accepts a file name as an argument, defaulting to the current
  directory, so a mere Enter takes a screenshot.  The user may choose
  another directory for taking the screenshot.  Also, if he selects an
  existing file name, a screen shot is not taken and that image is
  reused instead.  That may be useful when the same few images are
  overly used as inlined icons.  Try to not call "import" if the file
  name is plain wrong (no way to create a file under that name).

* No need to have the timestamp in the generated file name, as
  make-temp-name already adds a unique suffix.  No need to have overly
  long names, and if the timestamp is needed, "ls -l" will give it
  anyway.  The prefix of make-temp-name is made absolute, so it better
  checks that the file it creates does not spuriously exist.

* The minibuffer let the user know that a screenshot is expected.


P.S. ImageMagick "import" is quick and easy, but has a few limitations,
in that one cannot screenshot popups and menus.  When documenting the
usage of a program with a GUI, there are more flexible tools to take
screenshots in some special circumstances.  Should be parameterizable!
But for the needs I have this week, "import" is quite sufficient. :-)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]