blob: 489307e7c2071d8ccffae31c400419a5f4dcc83b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
|