From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4KgTMabdimDHtgAAgWs5BA (envelope-from ) for ; Thu, 29 Apr 2021 18:24:06 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id KIWyLKbdimCZNwAAB5/wlQ (envelope-from ) for ; Thu, 29 Apr 2021 16:24:06 +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 2A0E625934 for ; Thu, 29 Apr 2021 18:24:06 +0200 (CEST) Received: from localhost ([::1]:52882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc9SO-0004Rr-So for larch@yhetil.org; Thu, 29 Apr 2021 12:24:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc9Qs-0004RT-G7 for emacs-orgmode@gnu.org; Thu, 29 Apr 2021 12:22:32 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:46714) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lc9Qp-00042J-6w for emacs-orgmode@gnu.org; Thu, 29 Apr 2021 12:22:30 -0400 Received: by mail-wr1-x42a.google.com with SMTP id x5so17255656wrv.13 for ; Thu, 29 Apr 2021 09:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0zPzPOHYe3Uw3DcifOwoFuw4oNvB+Wk5ER7LID0+9wg=; b=ndcHrA9hhAYg33V7sbGSGiARCCEHifLhnAWyk6xWaNCedjuYydhLP6xsRMfKPJqCxo oJsrvp0zHZs+C9xNyqTva7cJDIEUn86PNQrzZpK9CxU6gM+jof1TEIxv/qZO7DOBHwQE qTUJrb70KBg2tmEaVG7+0vVDo9Qu7f3P45kt1rzqdZl/91LGs4cuDI4nBd6Tr8o+exCb U6xT1olwRHrKNDG12oDOf/v2kond3wYu6ZmW7QLLsr7FZdGtCUODVP/KnAVZ39jCiqTm N2cDHvOdIDTKmKcCAskHEf4C4KrsWuzw/pplr/zsuuJwIo4wCb7JeeOCwRDClIvFaQWr ZJzA== 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=0zPzPOHYe3Uw3DcifOwoFuw4oNvB+Wk5ER7LID0+9wg=; b=kZ0wlb1zrEZdzUU49+gOsNN2hkVDYpMJkNVu4ftcB5O5Kfw+Dm9I1VsYMrAQ3DFRrI syTTlG7lRJ0R7aMDzDKiNnJ0snU1/IkFk4IeQuhgQ0vBV3xQ4SjLTiW77epksiWGI/bK jVTf7YICHlbOXjvV+cZu32Qz/9kC4KN7dkRRzyUwcUf67lu7WdesPwVHPA0w0cTwcH2O yybrptR888cFEVKcvN+PfHkXh4Yk2Wb6oVjX6RLfe5HMeVuJzTeBgBO6EoPBvQAp8A8E L5FUum+ZXcgBlUdiLWulQcFK8CjYDoSAnrzRg20hOIZ2H+bBVXqs34b6OMF02n/mb+l2 VgVg== X-Gm-Message-State: AOAM531wtMYWTQ2tpx+K3lOqybWD7KEShm2D0xqtjnE6bmDw9H6Kspi3 V2HZ1+Efsr/ugxdGKF3gFlKeUdc+7rv4bu0plVk= X-Google-Smtp-Source: ABdhPJzDwVAPC+RdA1/E3tAbUibEIxbQZq7f7U2eXOwzk7uhc33hJ3nUlWYVbuJtQhUJFxEnxiaKYI+rRd6SuellVNk= X-Received: by 2002:adf:df01:: with SMTP id y1mr674946wrl.247.1619713344656; Thu, 29 Apr 2021 09:22:24 -0700 (PDT) MIME-Version: 1.0 References: <2acd022ab06f7f7e2fbe74a6b42d816a@condition-alpha.com> In-Reply-To: <2acd022ab06f7f7e2fbe74a6b42d816a@condition-alpha.com> From: Tim Visher Date: Thu, 29 Apr 2021 12:21:47 -0400 Message-ID: Subject: Re: How to use `open` to handle `message:*` links on macOS To: Alexander Adolf Content-Type: multipart/alternative; boundary="0000000000008bd6b305c11ee607" Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=tim.visher@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: 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=1619713446; 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=0zPzPOHYe3Uw3DcifOwoFuw4oNvB+Wk5ER7LID0+9wg=; b=GKcGL0l6feEAEl6dTbjE+RkdBQb4rqiNS5B5HWslSrkyRb0IA/Bj1Oo6LkTkRzuBupt/He anJvJ7xyATzFtSrm0K2QBq0iwqpxv5Ujy9KaQUCUNvgdixA8qf/u4B24W3Fl6/FE89vRCr A6MSvtLoCTTDMSap6A8baMjTl/R4oRzZm9Z/CTklLxO9+tDJ0j1gWuaxK1NO467j/g2tms +fiDt7LMthYvpgIbVLwNjcRjL1eeoBibH1iDdPFCV4Kjn+EbnNBP2iF93d3Bx9HT30b4Tf JEiCLvLLvKw413qu31qLZEeIC80RNz0acXHbwe3kEYTmkUxx7Mqf33yb6HXBYQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619713446; a=rsa-sha256; cv=none; b=XzMIqb8ntsNlBWbVjFLTgxY5hi0jzFT9atgUznnVKjbkjPnwHrl324t4k61h/ZlBv+Eruv qMuEup+SzsDfiJnw1WVV81eMzVswSagxrNL7p8mhXQj7933QJgTil+SCcMSSFO+hdwsjh8 +Ycms7nT1BYkF6AQmWs77A+yE0BQvsH9Hamt7xSPQwH/EKYUCrsp2m55sYkwdoxKOXJaGN Nsm2vGNwBK1uXJ3xUY+VxbMz9kCFr7ToAv+U/T3O0jrxeoFIP1yJ9A9+NQq1ChHR5JhA4W 45zzSczKmXcn9uulJkTvEX3n67n9dzHfS0vYP+9FloeL1LhYK7I7oG7UuRpCCw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ndcHrA9h; dmarc=pass (policy=none) header.from=gmail.com; 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: -3.16 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ndcHrA9h; dmarc=pass (policy=none) header.from=gmail.com; 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: 2A0E625934 X-Spam-Score: -3.16 X-Migadu-Scanner: scn0.migadu.com X-TUID: I39UwQgNVhPr --0000000000008bd6b305c11ee607 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=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)" :prepend t :immediate-finish t) =E2=80=A6)) Thanks so much! :) --0000000000008bd6b305c11ee607 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi Diego and Alexander,

Thanks for the tips here. I finally got around to t= rying them out. Here's what I ended up with and it's working perfec= tly.

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

--0000000000008bd6b305c11ee607--