- 安装snipaste截图软件(windows下,linux下使用flameshot/snippaste都可以);
- 在脚本中设置安装路径/或者系统里面环境变量应该也可以;
- 截图会直接插入到org-mode文件中,并且会在文件同样的目录下创建一个文件夹,并按照时间格式存储图片;
另外: 建议尽量不要使用中文文件名:因为创建的文件夹如果是中文,有可能window系统下snippaste识别成了乱码,如果需要使用中文,可能需要设置一下对用的路径的编码格式;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;org do screenshots and insert to org files
;;; windows use tool:snipaster
;;; linux use tool:flameshot
(defvar v-snip-exe-path "C:\\tools\\Snipaste\\Snipaste.exe")
;;if path-name has space
;;(defvar v-snip-exe-path "C:/\"Program Files\"/Snipaste/Snipaste.exe")
(defun v-org-snip-insert ()
"Take a screenshot into a unique-named file in the current buffer file
directory and insert a link to this file."
(interactive)
(lower-frame)
(let* ((capture-name (concat (format-time-string "%Y%m%d%H%M%S") ".png"))
(capture-imag-dir (concat "_images_" (file-name-nondirectory buffer-file-name) "/"))
(capture-save-path (concat (file-name-directory buffer-file-name) capture-imag-dir))
(capture-file (concat capture-save-path capture-name))
(v-org-file-path
(if (eq system-type `windows-nt)
(encode-coding-string (replace-regexp-in-string "/" "\\\\" capture-file) 'gbk)
capture-file
)))
(progn (message v-org-file-path)
(unless (file-exists-p capture-save-path)
(make-directory capture-save-path))
(if (eq system-type `windows-nt)
(progn ;;; if windows
(shell-command (concat v-snip-exe-path " snip -o \"" v-org-file-path "\""))) ;;
(progn ;;; if linux
(shell-command (concat "flameshot gui -p " v-org-file-path )))) ;;
;;(insert "#+CAPTATION: <typing in> \n")
;;(insert "#+LABEL: \n")
(insert (concat "[[./" capture-imag-dir capture-name "]]"))
;;(org-display-inline-images)
)))
(defun v-org-snip-del ()
"del org link and its file "
(interactive)
(beginning-of-line)
(search-forward "[[")
(setq path-string-begin (point))
(search-forward "png")
(setq path-string-end (point))
(setq v-line-path-get
(replace-regexp-in-string "/" "\\\\"
(buffer-substring path-string-begin path-string-end)))
(if (eq system-type `windows-nt)
(shell-command (concat "del " v-line-path-get))
(shell-command (concat "rm -rf " v-line-path-get)))
(beginning-of-line)
(kill-line))
(defun v-org-snip-del-region ()
"del org link and its file "
(interactive)
(narrow-to-region (region-beginning) (region-end))
(while (search-forward-regexp "\[\[.*_images.*org.*png\]\]")
(v-org-snip-del))
;;(widen)
)
(global-set-key (kbd "C-c p s") 'v-org-snip-insert)