From mboxrd@z Thu Jan 1 00:00:00 1970 From: pinard@iro.umontreal.ca (=?utf-8?Q?Fran=C3=A7ois?= Pinard) Subject: Re: [Orgmode] Automatic screenshot insertion Date: Wed, 04 Jan 2012 23:54:06 -0500 Message-ID: <87ehveyck1.fsf@iro.umontreal.ca> References: <4CE55F66.80802@gmail.com> <87vd3hmebo.wl%dmaus@ictsoc.de> <20110329144327.GE2902@x201> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:44329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Riqb1-0001c5-7G for emacs-orgmode@gnu.org; Thu, 05 Jan 2012 11:55:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Riqav-00012w-9p for emacs-orgmode@gnu.org; Thu, 05 Jan 2012 11:55:19 -0500 Received: from lo.gmane.org ([80.91.229.12]:42634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Riqau-00012q-UN for emacs-orgmode@gnu.org; Thu, 05 Jan 2012 11:55:13 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Riqat-0000Yh-De for emacs-orgmode@gnu.org; Thu, 05 Jan 2012 17:55:11 +0100 Received: from 206-248-137-202.dsl.teksavvy.com ([206.248.137.202]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 05 Jan 2012 17:55:11 +0100 Received: from pinard by 206-248-137-202.dsl.teksavvy.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 05 Jan 2012 17:55:11 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Russell Adams 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. :-)