Org-mode mailing list
 help / color / mirror / Atom feed
From: Aaron Jensen <aaronjensen@gmail.com>
To: emacs-orgmode@gnu.org
Cc: Aaron Jensen <aaronjensen@gmail.com>
Subject: [PATCH] org-mac-link: Disable Evernote capture by default
Date: Wed, 17 Feb 2021 09:53:32 -0600
Message-ID: <20210217155332.18162-1-aaronjensen@gmail.com> (raw)

The two `shell-command-to-string` invocations during eval are
extremely slow. Users of Evernote should `org-mac-grab-Evernote-app-p`
and `org-mac-evernote-path` explicitly.

* contrib/lisp/org-mac-link.el (org-mac-grab-Evernote-app-p): Default
to nil
(org-mac-evernote-path): Default to nil and add a function of the same
name that will either use the variable or a shell invocation to mdfind
(org-mac-evernote-note-open): Use the function version of org-mac-evernote-path
(org-as-get-selected-evernote-notes): Use the function version of
org-mac-evernote-path
---
 contrib/lisp/org-mac-link.el | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/contrib/lisp/org-mac-link.el b/contrib/lisp/org-mac-link.el
index e56354c4f..ec004d8b9 100644
--- a/contrib/lisp/org-mac-link.el
+++ b/contrib/lisp/org-mac-link.el
@@ -207,18 +207,13 @@
   :group 'org-mac-flagged-mail
   :type 'string)
 
-(defcustom org-mac-grab-Evernote-app-p
-  (< 0 (length (shell-command-to-string
-                "mdfind kMDItemCFBundleIdentifier == 'com.evernote.Evernote'")))
+(defcustom org-mac-grab-Evernote-app-p nil
   "Add menu option [e]vernote to grab note links from Evernote.app."
   :tag "Grab Evernote.app note links"
   :group 'org-mac-link
   :type 'boolean)
 
-(defcustom org-mac-evernote-path (replace-regexp-in-string (rx (* (any " \t\n")) eos)
-                                                           ""
-                                                           (shell-command-to-string
-                                                            "mdfind kMDItemCFBundleIdentifier == 'com.evernote.Evernote'"))
+(defcustom org-mac-evernote-path nil
   "The path to the installed copy of Evernote.app. Do not escape spaces as the AppleScript call will quote this string."
   :tag "Path to Evernote"
   :group 'org-mac-link
@@ -809,11 +804,21 @@ after heading."
 
 (org-link-set-parameters "mac-evernote" :follow #'org-mac-evernote-note-open)
 
+(defun org-mac-evernote-path ()
+  "Get path to evernote.
+First consider the value of ORG-MAC-EVERNOTE-PATH, then attempt to find it.
+Finding the path can be slow."
+  (or org-mac-evernote-path
+      (replace-regexp-in-string (rx (* (any " \t\n")) eos)
+                                ""
+                                (shell-command-to-string
+                                 "mdfind kMDItemCFBundleIdentifier == 'com.evernote.Evernote'"))))
+
 (defun org-mac-evernote-note-open (noteid _)
   "Open a note in Evernote"
   (do-applescript
    (concat
-    "tell application \"" org-mac-evernote-path "\"\n"
+    "tell application \"" (org-mac-evernote-path) "\"\n"
     "    set theNotes to get every note of every notebook where its local id is \"" (substring-no-properties noteid) "\"\n"
     "    repeat with _note in theNotes\n"
     "        if length of _note is not 0 then\n"
@@ -828,7 +833,7 @@ after heading."
   "AppleScript to create links to selected notes in Evernote.app."
   (do-applescript
    (concat
-    "tell application \"" org-mac-evernote-path "\"\n"
+    "tell application \"" (org-mac-evernote-path) "\"\n"
      "    set noteCount to count selection\n"
      "    if (noteCount < 1) then\n"
      "        return\n"
-- 
2.28.0



             reply	other threads:[~2021-02-17 15:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 15:53 Aaron Jensen [this message]
2021-02-27 13:14 ` Aaron Jensen
2021-02-27 22:58   ` Kyle Meyer
2021-02-28 11:11     ` Alan Schmitt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://orgmode.org

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210217155332.18162-1-aaronjensen@gmail.com \
    --to=aaronjensen@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git