diff options
-rw-r--r-- | init.el | 9 | ||||
-rw-r--r-- | lib/doc/jao-mac.el | 82 |
2 files changed, 80 insertions, 11 deletions
@@ -1801,13 +1801,16 @@ ("g" "ripgrep notes" jao-org-notes-consult-ripgrep)] ["Documents" ("d" "go to doc" jao-select-pdf) - ("o" "open doc" jao-open-doc)] + ("o" "open doc" jao-open-doc) + ("s" "open skim doc" jao-skim-open-current-doc) + ("c" "view cache" doc-view-dired-cache)] ["Network" - ("s" "ssh" jao-ssh) + ("S" "ssh" jao-ssh) ("r" "r2e" jao-r2e)] ["Utilities" ("l" "packages" jao-list-packages) - ("f" "copy buffer file name" copy-buffer-file-name-as-kill)]]) + ("f" "copy buffer file name" copy-buffer-file-name-as-kill) + ("N" "browse NNW article" jao-nnw-browse-current-article)]]) (transient-define-prefix jao-transient-utils () "Global operations." diff --git a/lib/doc/jao-mac.el b/lib/doc/jao-mac.el index f40ca10..c828507 100644 --- a/lib/doc/jao-mac.el +++ b/lib/doc/jao-mac.el @@ -21,19 +21,21 @@ (require 'jao-shell) ;;; Applescript -(defun jao-mac-run-applescript (script) - (let (start cmd return) +(defun jao-mac-applescript-prepare (&rest lines) + (let ((script (mapconcat 'identity lines "\r")) + (start)) (while (string-match "\n" script) (setq script (replace-match "\r" t t script))) (while (string-match "'" script start) (setq start (+ 2 (match-beginning 0)) script (replace-match "\\'" t t script))) - (setq cmd (concat "osascript -e '" script "'")) - (setq return (shell-command-to-string cmd)) - (string-trim return))) + script)) + +(defun jao-mac-run-applescript (script) + (string-trim (shell-command-to-string (format "osascript -e '%s'" script)))) -(defun jao-mac-run-applescript* (&rest script-lines) - (jao-mac-run-applescript (mapconcat 'identity script-lines "\r"))) +(defun jao-mac-run-applescript* (&rest lines) + (jao-mac-run-applescript (apply #'jao-mac-applescript-prepare lines))) (defun jao-mac-tell-app (app &rest script-lines) (let* ((app-id (string-split app)) @@ -41,7 +43,7 @@ (app (if (> (length app-id) 1) (cadr app-id) (car app-id))) (pre (list (format "tell application %s %S" id app))) (post '("end tell\n"))) - (jao-mac-run-applescript* (append pre script-lines post)))) + (apply #'jao-mac-run-applescript* (append pre script-lines post)))) ;;; open @@ -72,6 +74,70 @@ (format "keystroke %s" (or page 1)) "delay 0.1\rkeystroke return\rend tell"))) +;;; Skim +(defvar jao-skim--current-file-script + (jao-mac-applescript-prepare + "tell application \"Skim\"" + " try" + " set theD to front document" + " set theP to (path of theD)" + " set thePg to (get index of current page of theD)" + " return (theP & \"::\" & thePg)" + " on error" + " return \"\"" + " end try" + "end tell")) + +(defun jao-skim-current-doc () + "Returns a list of path and page number for the current Skim doc." + (when-let* ((p (jao-mac-run-applescript jao-skim--current-file-script))) + (let ((ps (split-string p "::"))) + (list (car ps) (string-to-number (cadr ps)))))) + +(defun jao-skim-open-current-doc () + (interactive) + (when-let* ((ps (jao-skim-current-doc))) + (apply 'jao-open-doc ps))) + +;;; NetNewsWire + +(defvar jao-nnw--current-article-script + (jao-mac-applescript-prepare + "tell application \"NetNewsWire\"" + "try" + "return (the url of the current article)" + "on error" + "return \"\"" + "end try" + "end tell")) + +(defun jao-nnw-current-article () + "The URL of the current article in NetNewsWire" + (jao-mac-run-applescript jao-nnw--current-article-script)) + +(defun jao-nnw-browse-current-article () + (interactive) + "Browse the URL of the current NNW article." + (if-let* ((url (jao-nnw-current-article))) + (unless (string-empty-p url) + (browse-url url)) + (message "No article selected in NetNewsWire"))) + +;;; Firefox +(defvar jao-ffox--current-url-script + (jao-mac-applescript-prepare + "tell application \"Firefox\" to activate" + "tell application \"System Events\"" + "keystroke \"l\" using command down" + "keystroke \"c\" using command down" + "end tell" + "delay 0.5" + "return the clipboard")) + +(defun jao-firefox-current-url () + (let ((res (jao-mac-run-applescript jao-ffox--current-url-script))) + (jao-mac-run-applescript "tell application \"Emacs\" to activate"))) + ;;; DevonThink (defun jao-devon-tell (&rest script-lines) |