4

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 '15 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 '15 at 23:25
  • 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 '15 at 15:07
2

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"))
        "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"))
       (exit-status 
        (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) "")
      (org-display-inline-images))))

(bind-key "C-S-y" 'org-insert-clipboard)

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.