2023-11-04 16:01:12-04:00 - Pasting images into org-mode files from the clipboard

I've long wanted to paste images into org-mode files as easy as one does with WYSIWYG editors. And today I figured out that you can do that with the org-download package and it's org-download-screenshot function! There was a helpful post at zzamboni.org that told how to do it on macOS. I adapted it to X and Wayland.

org-download

How to insert screenshots in Org documents on macOS

If you are using Wayland, install the wl-clipboard package. If you are using X, install the xclip page.

Then Install org-download and then use this config:

(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)
    :bind
    ("C-c k o d s" . org-download-screenshot)
    :config
    (require 'org-download)
    (cond ((getenv "WAYLAND_DISPLAY")
            ;; check for Wayland first because of X on Wayland
            (message "Wayland is here!")
            (setq org-download-screenshot-method
                  "wl-paste > %s"))
          ((getenv "DISPLAY")
           (message "X is here!")
           (setq org-download-screenshot-method
            "xclip -selection clipboard -t image/png -o > %s"))
          (t
           (message "Neither X nor Wayland are available."))))

Here's an org-mode file I've just pasted some images into:

pasting into org-mode files screenshot