As I’m taking notes or writing in Org-mode, I often want to insert screenshots inline with the text. While Org supports inserting and displaying inline images, the assumption is that the image is already somewhere in the file system and we just want to link to it.
The org-download package eases the task of downloading or copying images and attaching them to a document, and it even has an org-download-screenshot
command, but this assumes you want to initiate the screenshot from within Emacs, whereas the workflow I prefer is like this:
- Capture screenshot using the macOS built-in screenshot tool (Shift-⌘-5) and leave it in the clipboard.
- Paste the image into the document I’m working on.
Fortunately, org-download
allows customizing the command used by the org-download-screenshot
command. Together with the pngpaste utility, this can be used to make org-download-screenshot
store the image from the clipboard to disk, and insert it into the document. This is my configuration:
(use-package org-download
:after org
:defer nil
:custom
(org-download-method 'directory)
(org-download-image-dir "images")
(org-download-heading-lvl nil)
(org-download-timestamp "%Y%m%d-%H%M%S_")
(org-image-actual-width 300)
(org-download-screenshot-method "/usr/local/bin/pngpaste %s")
:bind
("C-M-y" . org-download-screenshot)
:config
(require 'org-download))
With this configuration, images are stored in a directory named images
under the current directory, in a flat directory structure and each file is prepended with a timestamp (I would prefer not to use timestamps, but org-download
uses a fixed filename for screenshots, which makes it difficult to insert multiple screenshots in the same document). You may want to check the org-download
documentation and configure these settings to your liking.
Finally, I bind org-download-screenshot
to Ctrl-⌘-y to keep it similar to the default Ctrl-y for pasting the clipboard and to easily perform step 2 of the workflow described above.
Now when I want to insert a screenshot in a document, I simply press Shift-⌘-5, capture the screenshot, switch back to Emacs, press Ctrl-⌘-y, and done. It looks like this:
And without inline image display, we can see that the screenshot is automatically stored inside the images/
directory: