Skip to content

Instantly share code, notes, and snippets.

Last active January 26, 2021 19:31
What would you like to do?
orgmode image inserter
(defun org-insert-image-from-clipboard ()
"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. Depends in to work (for now)"
(setq folder-name (concat (file-name-sans-extension (buffer-file-name)) "-orgimg"))
(message folder-name)
(if (not (file-directory-p folder-name))
(make-directory folder-name nil))
(setq filename
folder-name "/"
(concat ;(buffer-file-name) ;"-"
(format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
;; TODO: add switch to detect Xorg or wayland session using (getenv "XDG_SESSION_TYPE")
(if (string= (car (split-string
(concat "xclip -selection clip -t image/png -o >> " filename ))
":")) "Error")
(message "clipboard does not contain a image!")
(concat "[[./" (file-relative-name filename) "]]")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment