[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to use `open` to handle `message:*` links on macOS
From: |
Tim Cross |
Subject: |
Re: How to use `open` to handle `message:*` links on macOS |
Date: |
Fri, 30 Apr 2021 05:37:19 +1000 |
User-agent: |
mu4e 1.5.12; emacs 28.0.50 |
Tim Visher <tim.visher@gmail.com> writes:
> Hi Diego and Alexander,
>
> Thanks for the tips here. I finally got around to trying them out. Here's
> what I ended up with and it's working perfectly.
>
> (defun timvisher-org-link-mac-mail-open-link
> (mid _)
> (start-process "open-link" nil "open" (format "message://%%3C%s%%3E"
> mid)))
>
> (defun timvisher-org-link-mac-mail-add-message-links
> ()
> (org-link-set-parameters
> "message" :follow #'timvisher-org-link-mac-mail-open-link))
>
> (eval-after-load 'org
> '(timvisher-org-link-mac-mail-add-message-links))
>
> Pairing that with my org-capture TODO Current Mail Template is a dream come
> true. :)
>
> (defun timvisher-org-current-mail-get-selected-message-subject
> ()
> (with-temp-buffer
> (call-process
> "osascript" nil t nil
> "-e" "tell application \"Mail\" to get subject of item 1 of (selection
> as list)")
> (buffer-substring-no-properties (point-min) (- (point-max) 1))))
>
> (defun timvisher-org-current-mail-get-selected-message-id
> ()
> (with-temp-buffer
> (call-process
> "osascript" nil t nil
> "-e" "tell application \"Mail\" to get message id of item 1 of
> (selection as list)")
> (browse-url-url-encode-chars
> (buffer-substring-no-properties (point-min) (- (point-max) 1))
> "[/]")))
>
> (defun timvisher-org-current-mail-get-link-string
> ()
> (let ((subject (timvisher-org-current-mail-get-selected-message-subject))
> (message-id (timvisher-org-current-mail-get-selected-message-id)))
> (org-link-make-string (format "message:%s" message-id)
> subject)))
>
> (defun timvisher-org-current-mail-get-body-quote-template-element
> ()
> (let ((body (setq body (with-temp-buffer
> (call-process
> "osascript" nil t nil
> "-e" "tell application \"Mail\" to get content of item 1 of
> (selection as list)")
> (buffer-substring-no-properties (point-min) (- (point-max)
> 1))))))
> (format "
>
> #+begin_quote
> %s
> #+end_quote"
> (string-join
> (seq-reduce
> (lambda (acc next)
> (if (string= next (or (car (last acc)) ""))
> acc
> (append acc (list next))))
> (mapcar (lambda (string)
> (let ((string (string-trim string)))
> (if (string= "" string)
> string
> (format " %s" string))))
> (split-string body "\n"))
> '())
> "\n"))))
>
> (setq org-capture-templates
> '(…
> ("twcm" "TODO Work Current Mail" entry
> (file+headline "~/Dropbox/todo/work.org" "Inbox")
> "* TODO %(timvisher-org-current-mail-get-link-string)
>
> %U%(timvisher-org-current-mail-get-body-quote-template-element)" :prepend t
> :immediate-finish t)
> …))
>
> Thanks so much! :)
I think this would be great content to add to the worg site. Would you
be willing to add this, plus a short outline of the issue you needed to
resolve so that others might benefit from your experience?
--
Tim Cross