From 4e1e853f9a3b4da53d5004452ffade30532b3d63 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 7 Sep 2026 21:52:58 +0100 Subject: mac: wee refactorings --- lib/eos/jao-mac.el | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/eos/jao-mac.el b/lib/eos/jao-mac.el index ae13c0f..2312c6c 100644 --- a/lib/eos/jao-mac.el +++ b/lib/eos/jao-mac.el @@ -48,21 +48,32 @@ ;;; open +;;;###autoload (defun jao-mac-open (thing &rest args) "Invoke open after formatting thing with args, using `format'" (jao-shell-exec (format "open %s" (apply #'format thing args)))) -(declare-function 'doc-view-current-page "doc-view") +;;; notifications -(defun jao-mac-open-in-skim (&optional file page _height) - (interactive) - (let* ((file (if file (expand-file-name file) (buffer-file-name))) - (page (or page (and (derived-mode-p 'doc-view-mode) - (doc-view-current-page))))) - (jao-mac-open "skim://%s%s" file (if page (format "#page=%s" page) "")))) +(defun jao-mac-notify (title subtitle msg) + (jao-mac-run-applescript* + (format "display notification %S with title %S subtitle %S" + msg title subtitle))) + +(defun jao-mac-app-badge (app) + "A very hacky, yet efficient, way of getting and apps badge." + (let* ((c (format "lsappinfo info -app %S -only StatusLabel" app)) + (s (shell-command-to-string c))) + (when (string-match ".*=\"\\([0-9]+\\)\" ." s) + (string-to-number (match-string 1 s)))) ) + +;;; Preview + +(declare-function 'doc-view-current-page "doc-view") ;; https://alvinalexander.com/macos/applescript-how-to-open-pdf-file-in-preview-go-to-page/ ;; This will work as long as Preview is the default app for the file at hand. +;;;###autoload (defun jao-mac-open-in-preview (&optional file page _height) (interactive) (let ((file (if file (expand-file-name file) (buffer-file-name))) @@ -77,21 +88,8 @@ (format "keystroke %s" (or page 1)) "delay 0.1\rkeystroke return\rend tell"))) -;;; notifications - -(defun jao-mac-notify (title subtitle msg) - (jao-mac-run-applescript* - (format "display notification %S with title %S subtitle %S" - msg title subtitle))) -(defun jao-mac-app-badge (app) - "A very hacky, yet efficient, way of getting and apps badge." - (let* ((c (format "lsappinfo info -app %S -only StatusLabel" app)) - (s (shell-command-to-string c))) - (when (string-match ".*=\"\\([0-9]+\\)\" ." s) - (string-to-number (match-string 1 s)))) ) - -;;; dict +;;; Dict (defvar jao-mac-dict-history nil) @@ -104,8 +102,6 @@ (substring-no-properties word) t))) -;;(setq completion-auto-help nil) - ;;; Skim (defvar jao-skim--current-file-script (jao-mac-applescript-prepare @@ -141,6 +137,7 @@ (defun jao-skim-page-text () (jao-mac-run-applescript jao-skim--current-page-text)) +;;;###autoload (defun jao-skim-view-page-text () (interactive) (when-let* ((ps (jao-skim-current-doc)) @@ -160,6 +157,14 @@ (lnk (format "doc:%s::%s" file page))) (org-link-make-string lnk title))) +;;;###autoload +(defun jao-mac-open-in-skim (&optional file page _height) + (interactive) + (let* ((file (if file (expand-file-name file) (buffer-file-name))) + (page (or page (and (derived-mode-p 'doc-view-mode) + (doc-view-current-page))))) + (jao-mac-open "skim://%s%s" file (if page (format "#page=%s" page) "")))) + ;;;###autoload (defun jao-pdf-insert-skim-org-link () (interactive) -- cgit v1.2.3