diff options
Diffstat (limited to 'lib/doc/jao-devon.el')
-rw-r--r-- | lib/doc/jao-devon.el | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/doc/jao-devon.el b/lib/doc/jao-devon.el new file mode 100644 index 0000000..489307e --- /dev/null +++ b/lib/doc/jao-devon.el @@ -0,0 +1,55 @@ +;;; jao-devon.el --- Utilities to interact with devonthink -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 Jose Antonio Ortega Ruiz + +;; Author: Jose Antonio Ortega Ruiz <mail@jao.io> +;; Keywords: docs + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Searches and general scripting in devon. + +;;; Code: + +(defun jao-devon--do-applescript (script) + (let (start cmd return) + (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))) + +(defun jao-devon-tell (&rest script-lines) + (let ((scpt (mapconcat 'identity + (append (cons "tell application id \"DNtp\"" + script-lines) + '("end tell\n")) + "\n"))) + (jao-devon--do-applescript scpt))) + +(defun jao-devon-find-url (file) + (jao-devon-tell + "repeat with db in databases" + (format "set res to lookup records with path %S in db" (file-truename file)) + "if res /= {} then return the reference URL of (item 1 of res)" + "end repeat" + "return \"\"")) + +(provide 'jao-devon) +;;; jao-devon.el ends here |