From e6513a85cf53b6c7230e46e82bca66aa7eb7e28c Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Thu, 2 May 2024 18:14:02 -0700 Subject: [PATCH] Add org-screenshot --- thoom-emacs/modules/thoom-org.el | 44 +++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/thoom-emacs/modules/thoom-org.el b/thoom-emacs/modules/thoom-org.el index c084de1..a260336 100644 --- a/thoom-emacs/modules/thoom-org.el +++ b/thoom-emacs/modules/thoom-org.el @@ -2,11 +2,14 @@ (use-package org :bind (("C-c o ," . thoom/org-clear-all) + ("C-c o s" . org-screenshot) + ("C-c SPC" . org-table-blank-field) ;; Unbind to make room for avy :map org-mode-map ("C-j" . nil)) :custom - (org-todo-keywords '((sequence "TODO(t)" "BLOCKED(b)" "|" "DONE(d)")))) + (org-todo-keywords '((sequence "TODO(t)" "BLOCKED(b)" "|" "DONE(d)"))) + (org-image-actual-width '(800))) (use-package org-bullets :ensure t @@ -24,3 +27,42 @@ (org-todo ""))) ;;(flush-lines "CLOSED") (message "Entries cleared.")) + +;; Steps to set up: +;; 1. Install ShareX, add ShareX folder to PATH +;; 2. Create hotkey named GameNotes with settings: +;; Capture preconfigured window +;; Capture -> Pre configured window title: +;; Override after capture tasks to "Save image to file" +;; Override screenshots folder to org-screenshot-import-path +;; Override Upload settings -> File naming -> Name pattern +;; "GameNotes_%t_%y-%mo-%d-%h-%mi-%s.%ms" +;; 3. Put the following at the top of the org file: +;; #+STARTUP: inlineimages +;; #+ATTR_HTML: :width 500px +(defvar org-screenshot-import-path "/mnt/c/Users/thoom/Seafile/Games/Screenshots/") +(defvar org-screenshot-export-path org-screenshot-import-path) +(defvar org-screenshot-exec-path "ShareX.exe") +(defvar org-screenshot-exec-args "-s -workflow GameNotes") + +(defun org-screenshot () + (interactive) + (let* ((heading-name (org-get-heading t t t t)) + (_ (set-text-properties 0 (length heading-name) nil heading-name)) + (_ (shell-command (concat org-screenshot-exec-path " " org-screenshot-exec-args))) + (_ (sit-for 0.25)) + (in-file (car (nreverse (directory-files org-screenshot-import-path 'full "GameNotes.*.png")))) + (out-dir-name (file-name-sans-extension (file-name-nondirectory buffer-file-name))) + (out-dir (file-name-as-directory (concat (file-name-as-directory org-screenshot-export-path) out-dir-name))) + (out-file (concat out-dir heading-name "-" (org-id-uuid) ".png"))) + (if (and (stringp in-file) (file-exists-p in-file)) + (progn + (unless (file-exists-p out-dir) + (make-directory out-dir)) + (rename-file in-file out-file) + (message (format "Saved %S to %S" in-file out-file)) + (save-excursion + (org-next-visible-heading 1) + (org-open-line 1) + (org-insert-link nil out-file))) + (message "Failed to find saved screenshot."))))