Last active
January 26, 2021 19:31
-
-
Save Luctins/8fde406122f332d5d831e2cce1036e5f to your computer and use it in GitHub Desktop.
orgmode image inserter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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