As I\'m using the Emacs Org mode as a research log, sometime I want to keep track of something via screenshot images, and I definitely don\'t want to save them. So I\'m wonderin
For OS X users. The following compliments Assem's answer.
The import
command was not working for me, so I swapped it to screencapture
with an -i
argument. I also find it more convenient to use a relative path for the link rather than the absolute.
(defun my-org-screenshot ()
"Take a screenshot into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file."
(interactive)
(setq filename
(concat
(make-temp-name
(concat (file-name-nondirectory (buffer-file-name))
"_"
(format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
(call-process "screencapture" nil nil nil "-i" filename)
(insert (concat "[[./" filename "]]"))
(org-display-inline-images))
I have recently improved on the script a little. It now places screenshots in a subdirectory, creates the directory if required, and only inserts the link into emacs if the image was actually created (i.e., does nothing if you hit ESC). It also works on both Ubuntu and OS X.
(defun my-org-screenshot ()
"Take a screenshot into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file."
(interactive)
(org-display-inline-images)
(setq filename
(concat
(make-temp-name
(concat (file-name-nondirectory (buffer-file-name))
"_imgs/"
(format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
(unless (file-exists-p (file-name-directory filename))
(make-directory (file-name-directory filename)))
; take screenshot
(if (eq system-type 'darwin)
(call-process "screencapture" nil nil nil "-i" filename))
(if (eq system-type 'gnu/linux)
(call-process "import" nil nil nil filename))
; insert into file if correctly taken
(if (file-exists-p filename)
(insert (concat "[[file:" filename "]]"))))