emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Mike McLean <mike.mclean@pobox.com>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: [PATCH] Add Support for Evernote in Org-Mac Link
Date: Mon, 14 Dec 2015 13:08:54 -0500	[thread overview]
Message-ID: <CANid5Q7bHoi8w551WQfE1GrosTOeXU10UR+Ndhvx16AYFWkEqA@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 617 bytes --]

The attached patch adds support for Evernote Note links in
contrib/org-mac-link.el

Commit Message:

org-mac-link.el: Add support for Evernote Note Links

(org-mac-grab-Evernote-app-p, org-mac-evernote-path): New custom
variables to control Evernote grabbing
(org-mac-evernote-note-open): New function to open an Evernote note by
ID
(org-as-get-selected-evernote-notes,
org-mac-evernote-note-insert-selected): New functions to get the
selected Evernote note(s) and insert them into current buffer

Note this change also defines a new link type ("mac-evernote") via a
call to “org-add-link-type”.

[-- Attachment #1.2: Type: text/html, Size: 824 bytes --]

[-- Attachment #2: 0001-org-mac-link.el-Add-support-for-Evernote-Note-Links.patch --]
[-- Type: application/octet-stream, Size: 5646 bytes --]

From 48c7da6fd8e692c271c27f9ade2c7c6c32466ada Mon Sep 17 00:00:00 2001
From: Mike McLean <mike.mclean@pobox.com>
Date: Mon, 14 Dec 2015 12:55:25 -0500
Subject: [PATCH] org-mac-link.el: Add support for Evernote Note Links
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

(org-mac-grab-Evernote-app-p, org-mac-evernote-path): New custom
variables to control Evernote grabbing
(org-mac-evernote-note-open): New function to open an Evernote note by
ID
(org-as-get-selected-evernote-notes,
org-mac-evernote-note-insert-selected): New functions to get the
selected Evernote note(s) and insert them into current buffer

Note this change also defines a new link type ("mac-evernote") via a
call to “org-add-link-type”.
---
 contrib/lisp/org-mac-link.el | 72 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/contrib/lisp/org-mac-link.el b/contrib/lisp/org-mac-link.el
index e04fb80..5870b73 100644
--- a/contrib/lisp/org-mac-link.el
+++ b/contrib/lisp/org-mac-link.el
@@ -26,6 +26,10 @@
 ;; Author: Mike McLean <mike.mclean@pobox.com>
 ;; Make the path to Microsoft Outlook a `defcustom'
 ;;
+;; Version 1.5
+;; Author: Mike McLean <mike.mclean@pobox.com>
+;; Add Support for Evernote
+;;
 ;; This file is not part of GNU Emacs.
 ;;
 ;; This program is free software; you can redistribute it and/or modify
@@ -66,6 +70,7 @@
 ;; Skim.app - Grab a link to the selected page in the topmost pdf document
 ;; Microsoft Outlook.app - Grab a link to the selected message in the message list
 ;; DEVONthink Pro Office.app - Grab a link to the selected DEVONthink item(s); open DEVONthink item by reference
+;; Evernote.app - Grab a link to the selected Evernote item(s); open Evernote item by ID
 ;;
 ;;
 ;; Installation:
@@ -195,6 +200,23 @@
   :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'")))
+  "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'"))
+  "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
+  :type 'string)
+
 \f
 ;; In mac.c, removed in Emacs 23.
 (declare-function do-applescript "org-mac-message" (script))
@@ -226,6 +248,7 @@ When done, go grab the link, and insert it at point."
 	    ("f" "irefox" org-mac-firefox-insert-frontmost-url ,org-mac-grab-Firefox-app-p)
 	    ("v" "imperator" org-mac-vimperator-insert-frontmost-url ,org-mac-grab-Firefox+Vimperator-p)
 	    ("c" "hrome" org-mac-chrome-insert-frontmost-url ,org-mac-grab-Chrome-app-p)
+            ("e" "evernote" org-mac-evernote-note-insert-selected ,org-mac-grab-Evernote-app-p)
 	    ("t" "ogether" org-mac-together-insert-selected ,org-mac-grab-Together-app-p)
 	    ("S" "kim" org-mac-skim-insert-page ,org-mac-grab-Skim-app-p)
 	    ("A" "crobat" org-mac-acrobat-insert-page ,org-mac-grab-Acrobat-app-p)))
@@ -720,6 +743,55 @@ after heading."
 	(insert "\n")
 	(org-insert-heading nil t)
 	(insert org-heading "\n" (org-mac-outlook-message-get-links "f"))))))
+\f
+;; Handle links from Evernote.app
+
+(org-add-link-type "mac-evernote" 'org-mac-evernote-note-open)
+
+(defun org-mac-evernote-note-open (noteid)
+  "Open a note in Evernote"
+  (do-applescript
+   (concat
+    "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"
+    "            set _selectedNote to _note\n"
+    "        end if\n"
+    "    end repeat\n"
+    "    open note window with item 1 of _selectedNote\n"
+    "    activate\n"
+    "end tell")))
+
+(defun org-as-get-selected-evernote-notes ()
+  "AppleScript to create links to selected notes in Evernote.app."
+  (do-applescript
+   (concat
+    "tell application \"" org-mac-evernote-path "\"\n"
+     "    set noteCount to count selection\n"
+     "    if (noteCount < 1) then\n"
+     "        return\n"
+     "    end if\n"
+     "    set theLinkList to {}\n"
+     "    set theSelection to selection\n"
+     "    repeat with theNote in theSelection\n"
+     "        set theTitle to title of theNote\n"
+     "        set theID to local id of theNote\n"
+     "        set theURL to \"mac-evernote:\" & theID\n"
+     "        set theLink to theURL & \"::split::\" & theTitle & \"\n\"\n"
+     "        copy theLink to end of theLinkList\n"
+     "    end repeat\n"
+     "    return theLinkList as string\n"
+     "end tell\n")))
+
+(defun org-mac-evernote-note-insert-selected ()
+  "Insert a link to the notes currently selected in Evernote.app.
+This will use AppleScript to get the note id and the title of the
+note(s) in Evernote.app and make a link out of it/them."
+  (interactive)
+  (message "Org Mac Evernote: searching notes...")
+(insert (org-mac-paste-applescript-links
+	 (org-as-get-selected-evernote-notes))))
 
 \f
 ;; Handle links from DEVONthink Pro Office.app
-- 
2.6.4


             reply	other threads:[~2015-12-14 18:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-14 18:08 Mike McLean [this message]
2015-12-15 13:32 ` [PATCH] Add Support for Evernote in Org-Mac Link Alan Schmitt
2015-12-18 10:30 ` 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://www.orgmode.org/

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

  git send-email \
    --in-reply-to=CANid5Q7bHoi8w551WQfE1GrosTOeXU10UR+Ndhvx16AYFWkEqA@mail.gmail.com \
    --to=mike.mclean@pobox.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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 read-only IMAP folder(s) and NNTP newsgroup(s).