Last active
February 20, 2019 21:52
-
-
Save penghou620/01b44e2553e41b50dc43b72508a695c2 to your computer and use it in GitHub Desktop.
Insert screenshot/image from clipboard to orgmode
This file contains hidden or 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
;; Purpose: | |
;; Insert a image or a screenshot from the clipboard into a Org file. | |
;; | |
;; Requirements: | |
;; brew install pngpaste | |
;; | |
;; How to use: | |
;; 1. Copy the following code into your spacemacs init.el file. Put it inside the `dotspacemacs/user-init` function. | |
;; 1. Create a directory "attachments" in the same directory as your Org file. | |
;; 2. After you take a screenshot and the screenshot is in the clipboard, go back to your Org file and type `, i p` in sequence. | |
;; 3. The image should be inserted into your Org file and displayed inline. | |
;; | |
(defun org-insert-clipboard-image () | |
(interactive) | |
(let* ((the-dir (file-name-directory buffer-file-name)) | |
(attachments-dir (concat the-dir "attachments")) | |
(png-file-name (format-time-string "%a%d%b%Y_%H%M%S.png")) | |
(png-path (concat attachments-dir "/" png-file-name))) | |
(shell-command (concat "pngpaste " png-path)) | |
(insert (concat "[[" png-path "]]")) | |
(org-display-inline-images))) | |
(spacemacs/set-leader-keys-for-major-mode 'org-mode | |
"ip" 'org-insert-clipboard-image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment