I am planning to insert screenshot in org-capture buffer.

I have a function that can create a screenshot image in a images subdirectory of current directory. However, since the org-capture buffer is an indirect buffer, the buffer-file-name result is nil, it can not create the subdirectory directly.

So how can I get the original buffer path in org-template, save the screenshot in the images, and insert it to the org-capture buffer?

Of course, I can just finalize the org-capture buffer, go to the save place, and call screenshot function there. But it is kind of cumbersome, which i do not like very much. Please give me some hint if you have some idea. Thanks very much.

  • Can you use (buffer-name) instead of buffer-file-name?
    – mankoff
    Aug 12, 2015 at 16:26
  • I can get the buffer name, but still have no way to get the path to save screenshot.
    – Leu_Grady
    Aug 12, 2015 at 23:25
  • 1
    Ok. I didn't understand the question. Not sure how to do this. Have you looked at github.com/abo-abo/org-download ? It might do what you want...
    – mankoff
    Aug 13, 2015 at 15:07
  • Yes, I am using (org-download-clipboard) when in org-capture, but it does not allow to paste. Sep 12, 2022 at 13:22

1 Answer 1


I modified the screenshot function to adapt to take a screenshot in Org-capture buffer.

(defun org-insert-clipboard (&optional caption)
  (interactive "P")
  (let* ((image-dir
      (if (not (buffer-file-name))
          (let ((buffer-name (replace-regexp-in-string "CAPTURE-[0-9-]*" "" (buffer-name))))
        (concat (file-name-directory (buffer-file-name (get-file-buffer buffer-name))) "images"))
    (unless (file-exists-p image-dir)
      (make-directory image-dir))
    (let* ((image-file (concat image-dir "/" (format-time-string "%Y%m%d_%H%M%S") ".png"))
        (call-process"convert" nil nil nil 
             "clipboard:" image-file)))
      (if caption
      (insert (format "#+CAPTION: %s label:fig:%s\n" (read-input "Caption: ") (read-input "label: "))))
      (org-insert-link nil (concat"file:"image-file) "")

(bind-key "C-S-y" 'org-insert-clipboard)
  • How does this function affect the (org-download-clipboard) function? I am actually using (org-download-clipboard). Sep 12, 2022 at 13:23
  • This function is not working: it does not create a file, only the images folder. Sep 12, 2022 at 13:30
  • Do you have imagemagick installed on your system?
    – Leu_Grady
    Sep 16, 2022 at 7:13
  • Yes, I have it installed. Sep 16, 2022 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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