5

I am trying to pull together information that is scattered across a multipage PDF in an org buffer. The related items typically occupy a small region on a page only and may be many pages apart, hence the attempt to arrange them side by side in an org buffer where these images shall be included as a visual cue as org inline images along with a commentary.

Ideally, the region of interest would be drawn interactively as a rectangle and pasted in the org buffer in a way that saved the image locally in a subfolder next to the org file and inserted a link to the local file.

1) imagemagick
I am aware of "Automatic screenshot insertion” over at http://orgmode.org/worg/org-hacks.html which involves imagemagick and seems to do what I want except I see no obvious way to crop the screenshot before inserting the link. Saving the file first and cropping it manually is a stronger disruption of the workflow than I'd like since I expect lots of these.

2) accessing the system clipboard
Depositing a suitably cropped screenshot to the system's clipboard in OS X is easily done using grab.app. If this could be used, that'd be fine.

Any ideas?

3

I highly recommend org-download

https://github.com/abo-abo/org-download

its also very configurable and you can specify where to save the file, size etc

2

I modified the code you linked to on org-hacks to use scrot. This is a linux-only program, which, although no longer maintained, still works fine and allows you to interactively select the area of your screenshot.

(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)
  (let ((filename
         (concat
          (make-temp-name
           (concat (buffer-file-name)
                   "_"
                   (format-time-string "%Y%m%d_%H%M%S_")) ) ".png")))
    (call-process "scrot" nil nil nil "-s" filename)
    (insert (concat "[[" filename "]]"))
    (org-display-inline-images)))

Note that when you call this command, there is no visual indication that anything is happening! You just draw a rectangle with the mouse, and when you're done it inserts the resulting screenshot in the org buffer. It would be nice if the cursor changed shape or something to indicate that it was waiting for you to draw, but it doesn't.

1

This is a Mac specific approach that I use. You might be able to adapt it to the grab.app. I am not familiar with that app though.

;; adapted from [[https://vmtyler.com/applescript-markdown-ready-screenshots/][AppleScript Markdown-Ready Screenshots | VMTyler.com]]
(defun screenshot (&optional arg)
  "Take a screenshot and insert org link.
with prefix arg, minimize emacs first.
Only works on Mac OSX."
  (interactive "P")
  (when arg
    (suspend-frame))

  (unless (f-directory? "screenshots")
    (make-directory "screenshots"))
  (sit-for 0.2)

  (let ((fname (concat (format-time-string "date-%d-%m-%Y-time-%H-%M-%S" (current-time)) ".png")))
    (do-applescript
     (mapconcat
      'identity 
      (list (format "set screenshotFilePath to \"%s\"" (expand-file-name fname "screenshots"))
        "do shell script \"screencapture \" & \"-s\" & \" \" & quoted form of screenshotFilePath"
        (concat "set result to \"[[./" fname "]]\"")
        "set the clipboard to result")
      "\n"))
    (insert (format "\n\n#+attr_org: :width 300\n[[./%s]]\n\n" (concat "screenshots/" fname)))
    (org-redisplay-inline-images)
    (raise-frame)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.