emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: pinard@iro.umontreal.ca (François Pinard)
To: emacs-orgmode@gnu.org
Subject: Re: [Orgmode] Automatic screenshot insertion
Date: Wed, 04 Jan 2012 23:54:06 -0500	[thread overview]
Message-ID: <87ehveyck1.fsf@iro.umontreal.ca> (raw)
In-Reply-To: 20110329144327.GE2902@x201

Russell Adams <RLAdams@AdamsInfoServ.Com> 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
                (make-temp-name
                 (concat (file-name-as-directory name)
                         (subst-char-in-string
                          "." "-"
                          (file-name-sans-extension (buffer-file-name)))))
                ".png")))
  (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 "]]"))
  (org-display-inline-images))


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.

François


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. :-)

  parent reply	other threads:[~2012-01-05 16:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-18 17:16 Automatic screenshot insertion Jonathan BISSON
2010-11-18 17:50 ` Sébastien Vauban
2010-11-28 19:35 ` David Maus
2011-03-29 14:43   ` [Orgmode] " Russell Adams
2011-06-06 18:59     ` David Maus
2012-01-05  4:54     ` François Pinard [this message]
2012-01-09 18:27       ` Eric S Fraga
2012-01-09 20:22         ` François Pinard
2012-01-10  8:57           ` Eric S Fraga
2012-01-10 14:53             ` François Pinard
2012-01-10 16:08               ` Eric S Fraga
2012-01-10 19:27                 ` François Pinard
2012-01-10 19:46                   ` Skip Collins
2012-01-11  5:50                     ` Jambunathan K
2012-01-12  5:26                       ` Skip Collins
2012-01-12  6:26                         ` Thomas S. Dye
2012-01-14 21:35                     ` François Pinard
2012-01-15  6:37                       ` Marcelo de Moraes Serpa
2012-01-15 12:10                         ` Russell Adams
2012-01-15 19:31                           ` Marcelo de Moraes Serpa
2012-01-15 21:45                             ` Russell Adams
2012-01-10 20:26                   ` Eric S Fraga
2011-02-03 13:33 ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ehveyck1.fsf@iro.umontreal.ca \
    --to=pinard@iro.umontreal.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).