/
org-devonthink.el
50 lines (41 loc) · 1.5 KB
/
org-devonthink.el
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
;;; org-devonthink.el - Support for links to dtp messages by their UUID
;; version 1.1, by John Wiegley <johnw@gnu.org>
(require 'org)
(org-add-link-type "x-devonthink-item" 'org-dtp-open)
(defun org-dtp-open (record-location)
"Visit the dtp message with the given Message-ID."
(shell-command (concat "open x-devonthink-item:" record-location)))
(defun org-get-dtp-link (&optional given-name)
(interactive)
(let ((name (or given-name
(do-applescript (format "
tell application \"DEVONthink Pro\"
get name of content record
end tell"))))
(location (do-applescript (format "
tell application \"DEVONthink Pro\"
get uuid of content record
end tell"))))
(org-make-link-string
(concat "x-devonthink-item://" location) name)))
(defun org-insert-dtp-link ()
(interactive)
(let (name)
(when (region-active-p)
(setq name (buffer-substring-no-properties (region-beginning)
(region-end)))
(delete-region (region-beginning) (region-end)))
(insert (org-get-dtp-link name))))
(defun org-dtp-store-link ()
"Store a link to an dtp e-mail message by Message-ID."
(let ((link-name
(with-temp-buffer
(clipboard-yank)
(buffer-string))))
(org-store-link-props
:type "x-devonthink-item"
:link (cons (concat "x-devonthink-item://" link-name)
(concat "x-devonthink-item://" link-name))
:description (file-name-nondirectory link-name))))
(provide 'org-devonthink)
;;; org-devonthink.el ends here