Skip to content

Instantly share code, notes, and snippets.

@Luctins
Last active January 26, 2021 19:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luctins/8fde406122f332d5d831e2cce1036e5f to your computer and use it in GitHub Desktop.
Save Luctins/8fde406122f332d5d831e2cce1036e5f to your computer and use it in GitHub Desktop.
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 X.org to work (for now)"
(interactive)
(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
(concat
folder-name "/"
(make-temp-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")
(insert
(if (string= (car (split-string
(shell-command-to-string
(concat "xclip -selection clip -t image/png -o >> " filename ))
":")) "Error")
(message "clipboard does not contain a image!")
(concat "[[./" (file-relative-name filename) "]]")))
(org-display-inline-images))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment