emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to use `open` to handle `message:*` links on macOS
@ 2021-01-11 19:44 Tim Visher
  2021-01-11 21:57 ` Diego Zamboni
  2021-01-15 14:12 ` Alexander Adolf
  0 siblings, 2 replies; 11+ messages in thread
From: Tim Visher @ 2021-01-11 19:44 UTC (permalink / raw)
  To: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 347 bytes --]

Hi Everyone,

I'd like to be able to whack `C-c C-o` on `message:*` links on macOS and
have it call `open` on the contents. Is there a way to make that happen?

My intent is to be able to save a deep link to a Mail.app message in an org
document.

Thanks in advance!

--

In Christ,

Timmy V.

https://blog.twonegatives.com
http://five.sentenc.es

[-- Attachment #2: Type: text/html, Size: 557 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-01-11 19:44 How to use `open` to handle `message:*` links on macOS Tim Visher
@ 2021-01-11 21:57 ` Diego Zamboni
  2021-01-15 14:12 ` Alexander Adolf
  1 sibling, 0 replies; 11+ messages in thread
From: Diego Zamboni @ 2021-01-11 21:57 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 574 bytes --]

Hi Tim,

Look at the org-mac-link package from org-contrib, it allows doing this for
Mail.app and other Msc apps.

--Diego

On Mon, 11 Jan 2021 at 20:47, Tim Visher <tim.visher@gmail.com> wrote:

> Hi Everyone,
>
> I'd like to be able to whack `C-c C-o` on `message:*` links on macOS and
> have it call `open` on the contents. Is there a way to make that happen?
>
> My intent is to be able to save a deep link to a Mail.app message in an
> org document.
>
> Thanks in advance!
>
> --
>
> In Christ,
>
> Timmy V.
>
> https://blog.twonegatives.com
> http://five.sentenc.es
>

[-- Attachment #2: Type: text/html, Size: 1213 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-01-11 19:44 How to use `open` to handle `message:*` links on macOS Tim Visher
  2021-01-11 21:57 ` Diego Zamboni
@ 2021-01-15 14:12 ` Alexander Adolf
  2021-04-29 16:21   ` Tim Visher
  1 sibling, 1 reply; 11+ messages in thread
From: Alexander Adolf @ 2021-01-15 14:12 UTC (permalink / raw)
  To: Tim Visher, Emacs Org Mode mailing list

Hello Tim,

Tim Visher <tim.visher@gmail.com> writes:

> [...]
> I'd like to be able to whack `C-c C-o` on `message:*` links on macOS and
> have it call `open` on the contents. Is there a way to make that happen?
>
> My intent is to be able to save a deep link to a Mail.app message in an org
> document.
> [...]

In my setup, I'm using this:
---------------------------- Begin Quote -----------------------------
(org-add-link-type "mac-mail" 'org-mac-mail-link-open)

(defun org-mac-mail-link-open (mid)
  "Visit the email message with message id MID."
  (start-process "open-mail" nil "open" (format "message:%%3C%s%%3E" mid)))
----------------------------- End Quote ------------------------------

It gives me a new link type "mac-mail" for org-insert-link. Copy the
message ID (without the angle brackets) from Mail.app, and insert it as
the link location. This is a manual process, of course, but then I'm not
using it often, and I don't need it for anything else but Mail.app.

org-mac-link as suggested by Diego offers much more convenience by
automating the entire process, and by giving you access to many other
apps, too. So you might prefer that if you are going to use it often.


Hoping to have helped,

  --alex


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-01-15 14:12 ` Alexander Adolf
@ 2021-04-29 16:21   ` Tim Visher
  2021-04-29 16:28     ` Diego Zamboni
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Tim Visher @ 2021-04-29 16:21 UTC (permalink / raw)
  To: Alexander Adolf; +Cc: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 2964 bytes --]

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! :)

[-- Attachment #2: Type: text/html, Size: 6720 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-04-29 16:21   ` Tim Visher
@ 2021-04-29 16:28     ` Diego Zamboni
  2021-04-29 19:37     ` Tim Cross
  2021-04-29 23:38     ` Alexander Adolf
  2 siblings, 0 replies; 11+ messages in thread
From: Diego Zamboni @ 2021-04-29 16:28 UTC (permalink / raw)
  To: Tim Visher; +Cc: Alexander Adolf, Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 3294 bytes --]

Hi Tim,

Cool - thanks for the code! I may use it to improve my email capture
workflow :)

--Diego


On Thu, Apr 29, 2021 at 6:23 PM Tim Visher <tim.visher@gmail.com> wrote:

> 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! :)
>

[-- Attachment #2: Type: text/html, Size: 7121 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-04-29 16:21   ` Tim Visher
  2021-04-29 16:28     ` Diego Zamboni
@ 2021-04-29 19:37     ` Tim Cross
  2021-04-29 21:01       ` Tim Visher
  2021-04-29 23:38     ` Alexander Adolf
  2 siblings, 1 reply; 11+ messages in thread
From: Tim Cross @ 2021-04-29 19:37 UTC (permalink / raw)
  To: emacs-orgmode


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-04-29 19:37     ` Tim Cross
@ 2021-04-29 21:01       ` Tim Visher
  0 siblings, 0 replies; 11+ messages in thread
From: Tim Visher @ 2021-04-29 21:01 UTC (permalink / raw)
  To: Tim Cross; +Cc: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 738 bytes --]

On Thu, Apr 29, 2021 at 3:40 PM Tim Cross <theophilusx@gmail.com> wrote:

>
> Tim Visher <tim.visher@gmail.com> writes:
>
> > 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.
> >
> > …
> >
> > Pairing that with my org-capture TODO Current Mail Template is a dream
> come true. :)
> >
> > …
>
> 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?
>

I'd be happy to if you wouldn't mind shepherding me through the process a
bit. How does one go about "add[ing] to the worg site"? :)

[-- Attachment #2: Type: text/html, Size: 1150 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-04-29 16:21   ` Tim Visher
  2021-04-29 16:28     ` Diego Zamboni
  2021-04-29 19:37     ` Tim Cross
@ 2021-04-29 23:38     ` Alexander Adolf
  2021-05-02 20:58       ` Tim Visher
  2 siblings, 1 reply; 11+ messages in thread
From: Alexander Adolf @ 2021-04-29 23:38 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Org Mode mailing list

Hello Tim,

Tim Visher <tim.visher@gmail.com> writes:

> [...]
> 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.
> [...]

Glad I could be of assistance!

> Pairing that with my org-capture TODO Current Mail Template is a dream come
> true. :)
> [...]

That's interesting how you pull the information from Mail app.

How do you trigger the capture? Do you have to select the message in
Mail app, then move over to Emacs and trigger the capture there? or do
you have a way to trigger the Emacs capture from within Mail app?

The next level of productivity could perhaps be to switch to notmuch[1],
and do all you email from within Emacs. Use yasnippet[2] for composing
mails. And have snippets be presented to you by company[3]. Just
saying... ;-)

[1] https://notmuchmail.org/
[2] http://joaotavora.github.io/yasnippet/
[3] https://company-mode.github.io/

Cheers,

  --alexander


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-04-29 23:38     ` Alexander Adolf
@ 2021-05-02 20:58       ` Tim Visher
  2021-05-06 17:04         ` Alexander Adolf
  0 siblings, 1 reply; 11+ messages in thread
From: Tim Visher @ 2021-05-02 20:58 UTC (permalink / raw)
  To: Alexander Adolf; +Cc: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 1603 bytes --]

Hi Alexander,

On Thu, Apr 29, 2021 at 7:38 PM Alexander Adolf <
alexander.adolf@condition-alpha.com> wrote:

> Tim Visher <tim.visher@gmail.com> writes:
>
> > Pairing that with my org-capture TODO Current Mail Template is a dream
> come
> > true. :)
> > [...]
>
> That's interesting how you pull the information from Mail app.
>
> How do you trigger the capture? Do you have to select the message in
> Mail app, then move over to Emacs and trigger the capture there? or do
> you have a way to trigger the Emacs capture from within Mail app?
>
> The next level of productivity could perhaps be to switch to notmuch[1],
> and do all you email from within Emacs. Use yasnippet[2] for composing
> mails. And have snippets be presented to you by company[3]. Just
> saying... ;-)
>
> [1] https://notmuchmail.org/
> [2] http://joaotavora.github.io/yasnippet/
> [3] https://company-mode.github.io/


I do indeed trigger the capture by switching over to Emacs and whacking my
org-capture keybinding (`C-c C`). I have a todo item that's been sitting in
my list for a very long time to figure out how to move my email habits into
emacs but I've never gotten around to it. In this case it's even worse
because the only reason I'm using Mail.app in the first place is because my
work email got moved to an Exchange server so I now don't have a good web
based interface to read mail anymore like my beloved Gmail.

One of these days though I'm going to break the habit and move email
directly into Emacs. :)

Thanks for the tips again!

--

In Christ,

Timmy V.

https://blog.twonegatives.com
http://five.sentenc.es

[-- Attachment #2: Type: text/html, Size: 2502 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-05-02 20:58       ` Tim Visher
@ 2021-05-06 17:04         ` Alexander Adolf
  2021-05-06 17:38           ` Tim Visher
  0 siblings, 1 reply; 11+ messages in thread
From: Alexander Adolf @ 2021-05-06 17:04 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Org Mode mailing list

Hello Tim,

Tim Visher <tim.visher@gmail.com> writes:

> [...]
> I do indeed trigger the capture by switching over to Emacs and whacking my
> org-capture keybinding (`C-c C`). I have a todo item that's been sitting in
> my list for a very long time to figure out how to move my email habits into
> emacs but I've never gotten around to it. In this case it's even worse
> because the only reason I'm using Mail.app in the first place is because my
> work email got moved to an Exchange server so I now don't have a good web
> based interface to read mail anymore like my beloved Gmail.
>
> One of these days though I'm going to break the habit and move email
> directly into Emacs. :)

I was in the exact same situation as you until about half a year ago,
which was when I decided to (finally) act on my "move email to emacs"
task.

Coincidentally I have recently released a blog post covering some of the
basic aspects of planning the switch:

                https://condition-alpha.com/blog/?p=1792

IMO, a decent amount up-front planning is crucial. With notmuch, emacs's
mail message handling infrastructure, and elisp, anything is possible;
the sky is the limit. Email is too central to our daily work to start
with the defaults and see where it takes you (IMO). So think well what
your dream email workflow is, and then work towards that.

The smallest, and most isolated task is perhaps configuring msmtp for
sending mail; so why not start with that?

Importing existing mailboxes (from Apple's mail app in my case), is
another important issue (which I'll cover in a future blog post).

Once you've imported some mail, you can toy around with notmuch in
emacs, and the settings, until you get a gist of how things work, and
how far you are from your goal. Your everyday real work is still in
Apple's mail app.

Once you're confident that you'll be able to survive with your emacs
setup, then you can make the move, and stop using Apple's mail app.

If you start a big all-in-one migration, and it fails, you're left with
a big mess. Thus, doing things step-by-step with an option to revert
each step if it doesn't work, is crucial, too.


Hoping to have helped,

  --alexander


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use `open` to handle `message:*` links on macOS
  2021-05-06 17:04         ` Alexander Adolf
@ 2021-05-06 17:38           ` Tim Visher
  0 siblings, 0 replies; 11+ messages in thread
From: Tim Visher @ 2021-05-06 17:38 UTC (permalink / raw)
  To: Alexander Adolf; +Cc: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]

On Thu, May 6, 2021 at 1:04 PM Alexander Adolf <
alexander.adolf@condition-alpha.com> wrote:

>
> Tim Visher <tim.visher@gmail.com> writes:
>
> > [...]
> >
> > One of these days though I'm going to break the habit and move email
> > directly into Emacs. :)
>
> I was in the exact same situation as you until about half a year ago,
> which was when I decided to (finally) act on my "move email to emacs"
> task.
>
> Coincidentally I have recently released a blog post covering some of the
> basic aspects of planning the switch:
>
>                 https://condition-alpha.com/blog/?p=1792
>
> …
>
> The smallest, and most isolated task is perhaps configuring msmtp for
> sending mail; so why not start with that?
>
> …
>
> If you start a big all-in-one migration, and it fails, you're left with
> a big mess. Thus, doing things step-by-step with an option to revert
> each step if it doesn't work, is crucial, too.
>

Great advice and info all around! Thanks so much. :)

[-- Attachment #2: Type: text/html, Size: 1548 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-05-06 17:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 19:44 How to use `open` to handle `message:*` links on macOS Tim Visher
2021-01-11 21:57 ` Diego Zamboni
2021-01-15 14:12 ` Alexander Adolf
2021-04-29 16:21   ` Tim Visher
2021-04-29 16:28     ` Diego Zamboni
2021-04-29 19:37     ` Tim Cross
2021-04-29 21:01       ` Tim Visher
2021-04-29 23:38     ` Alexander Adolf
2021-05-02 20:58       ` Tim Visher
2021-05-06 17:04         ` Alexander Adolf
2021-05-06 17:38           ` Tim Visher

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).