From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id iDKdIDnnimAcOwEAgWs5BA (envelope-from ) for ; Thu, 29 Apr 2021 19:04:57 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 0IYoHDnnimCmWgAAbx9fmQ (envelope-from ) for ; Thu, 29 Apr 2021 17:04:57 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BA9EC26916 for ; Thu, 29 Apr 2021 19:04:56 +0200 (CEST) Received: from localhost ([::1]:59186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcA5u-00048M-L3 for larch@yhetil.org; Thu, 29 Apr 2021 13:04:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc9Wz-0007ic-7T for emacs-orgmode@gnu.org; Thu, 29 Apr 2021 12:28:49 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:35523) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lc9Wx-0006t8-21 for emacs-orgmode@gnu.org; Thu, 29 Apr 2021 12:28:48 -0400 Received: by mail-wm1-x331.google.com with SMTP id 26-20020a05600c22dab029013efd7879b8so71232wmg.0 for ; Thu, 29 Apr 2021 09:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zzamboni-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5J2b4urG7ukskBqGc74YUsMcseeMtu/s17T0MoAr33s=; b=SR1f/QLepbGVF4M/im47jyv1NgQGhuJtKOq/DJEzax5zjCDlWlqt7GezGJK6Nyh5Tw UoBGXg+iLQUeUWAHmrhZbRQnBZAMo3MN5mQkRFCJt3/a9xp46Hjkc9NddvrOEabz7Plp eb27J8n+VtuoZbOAyk1Q7ZkLcgonnKg1WX4ifI8PmakltOTjJqSwHEmkM8ZpHx0xXE7Z btU1mEWK7Waqa424b/EleMx/ib5n94C3R8ipPw+BejpPrwIOLYsXzcsy0Q1feUJipvQ2 /qaZ8csMAMwHuZXRC1nzq3n7/n8CRRJ+WAPeoStd1Et7/wWqHuy4mwOrwl7bBFb93vCs Sy6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5J2b4urG7ukskBqGc74YUsMcseeMtu/s17T0MoAr33s=; b=hf0DIHVzIRxUGWrRfgBusXAO4aOdSG1Tpo3pioHpUtIQdtrttm7GXc6qxBuS6286ky fIrrTpBZbLJeV8xG8CEEVlBehHmYj+dWgUumxR4FDPJxz7fQ3oHM+1yh/QzwcNcDac6r Q4WFvwDFwPgdkS42u9pIi5zM0kLLCHU8ULeO+lCuwAlo5eM9eycjCh/5zxx4apmD82HK 0D17b6o2PDjhBVeNDRiw6+KwzxERKrJTi/4zwKb5oi9+BMlM1siluP9VSv0+tS1/BkW9 0uZYQfJJGHUdFFpZYc2jKOA7mTZtQNG59VPoWXWRRL1ymnOGf0Kgv30mwqq5+Lyfzfgb ngBw== X-Gm-Message-State: AOAM530fmTjVjz4RTrfryakeQUP0YRxFb1fmduIKBhssROC4Cr1RJn4X x8oV4a0c8TKf7ftMk52FyYBS4yYfH6uaWn2nZJ05Nw== X-Google-Smtp-Source: ABdhPJzpaeIBJd/7Oikhrd5MkSiiy2uPweqsS1ckzz3XzAlQWSfPErQsVD5YnWrKh81nReD0Ww97MjSt7VbTWDuhY/g= X-Received: by 2002:a05:600c:4f13:: with SMTP id l19mr11744989wmq.47.1619713724499; Thu, 29 Apr 2021 09:28:44 -0700 (PDT) MIME-Version: 1.0 References: <2acd022ab06f7f7e2fbe74a6b42d816a@condition-alpha.com> In-Reply-To: From: Diego Zamboni Date: Thu, 29 Apr 2021 18:28:33 +0200 Message-ID: Subject: Re: How to use `open` to handle `message:*` links on macOS To: Tim Visher Content-Type: multipart/alternative; boundary="0000000000002fdaf305c11efdc9" Received-SPF: none client-ip=2a00:1450:4864:20::331; envelope-from=diego@zzamboni.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Adolf , Emacs Org Mode mailing list Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619715897; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=5J2b4urG7ukskBqGc74YUsMcseeMtu/s17T0MoAr33s=; b=h/FRq3pcwBaQwIy5OuLoV0AhxHg3ptAUG9XD8GhkBRQeRTzzOsUepPe3qhJrRU4Wsk8+OJ 7XPOX08ui83vH/twxQwSryN9OFaH01N9Irakq3RxCBGKiD8dhA//LaCjTrBD1Nj1x9UMBl /ktBFNrsBXYM8f8jW2Mit9dHsgy9mkbVyDFNHZeHbvAbUgnvoWreKyjdnooc1IRWCSZNvB wfF3Zqd8/QHf6WxmiK3y2S3xcgpuZ1xmC1IId67O6qfLipsNGrtZNHeTdAWDsWJU2rpSqJ H8a6XXvd8dCQCcQRBo/1hGkjhyIaZ2DWe7XXhXeT/eIYQUDIawvL5zCqDBJeqA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619715897; a=rsa-sha256; cv=none; b=RWy/ooXDVNpjyNrlsHmx0SjJpzHYMT4dslIe+IKY5DFeo22kPxEvaINWh9siNhqB9LhWHa P4dNPbUuupZOKCc+t/2vlvpVos2TWk8BdHm3Fikm98HGOr2VA5iJSAP1GB/4n6TXPDf+TR 5IAxrYaeu9dxZ73iY9eZ9GmLEWK/x18tUxi0M3uaVxSQjb/hr73PYDYBqipjslkdLUcK46 EJDWQJUiLrmaBDk3uVhncC8IPeiyvUCOC9pQAaMLy3eNyHFPAiJQBUibIjeLDhjgXI+qNP p7JqANM/K9k+M6Zfe4pbqQFLcFBtoGNN8zAhOvy8cfDSnkZiABaUZGdvdIcMeA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=zzamboni-org.20150623.gappssmtp.com header.s=20150623 header.b="SR1f/QLe"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.66 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=zzamboni-org.20150623.gappssmtp.com header.s=20150623 header.b="SR1f/QLe"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: BA9EC26916 X-Spam-Score: -2.66 X-Migadu-Scanner: scn0.migadu.com X-TUID: xGf0Ziyk95H7 --0000000000002fdaf305c11efdc9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 (selecti= on 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 (sele= ction 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-ma= x) 1)))))) > (format " > #+begin_quote%s #+end_quote" > (string-join > (seq-reduce > (lambda (acc next) > (if (string=3D next (or (car (last acc)) "")) > acc > (append acc (list next)))) > (mapcar (lambda (string) > (let ((string (string-trim string))) > (if (string=3D "" string) > string > (format " %s" string)))) > (split-string body "\n")) > '()) > "\n")))) > > (setq org-capture-templates > '(=E2=80=A6 > ("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)" :prepe= nd t :immediate-finish t) > =E2=80=A6)) > > Thanks so much! :) > --0000000000002fdaf305c11efdc9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Tim,

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

= --Diego


On Thu, Apr 29, 2021 at 6:23 PM Tim Visher &l= t;tim.visher@gmail.com> wrot= e:

Hi Die= go and Alexander,

Thanks for the tips here. I finally got around to trying them ou= t. 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" (f=
ormat "message://%%3C%s%%3E"=

                                                mid)))

(defun timvisher-org-link-mac-mail-add-message-links
    ()
  (org-link-set-parameters
   "message" :follow #'timvisher-org-link-mac-ma=
il-open-link))

(eval-after-load 'org
  '(timvisher-org-link-mac-mail-add-message-links))

Pairing that with my=C2=A0org-capture=C2=A0TODO 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-or=
g-current-mail-get-selected-message-subject))
        (message-id (timvisher-org-current-mail-get-selected-message-id)))
    (org-link-make-string (format &quo=
t;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\&=
quot; 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 nex=
t)
                (if (string=3D=
 next (or (car (last acc)) ""))
                    acc
                  (append acc (list next))))
              (mapcar (lambda =
(string)
                        (let (=
(string (string-trim string)))
                          (if =
(string=3D "" string)
                              string
                            (format &q=
uot;  %s" string))))
                      (split-string body "\n"))
              '())
             "\n"))))

(setq org-capture-templates
      '(=E2=80=A6
        ("twcm" "TODO Work=
 Current Mail" entry
         (file+headline "~/Dropbo=
x/todo/work.org" "Inbox")
         "* TODO %(timvisher-org-current-mail-get-link-string)

  %U%(timvisher-org-current-mail-get-b=
ody-quote-template-element)" :prepend t :immediate-finish=
 t)
        =E2=80=A6))

Thanks so much! :)

--0000000000002fdaf305c11efdc9--