DEVONthink to Evernote Exporter

Shared By: Justin

Description

Updated on April 7, 2012

This script exports an copy of selected DEVONthink items and saves them into Evernote, applying the Group Name in DEVONthink as a tag in Evernote. To use it, just highlight the items in DEVONthink that you want to send to Evernote and run the script!

Moving Items By Script Vs. Moving By Email

One fast way to get items into Evernote is simply to email them. Brett Kelly’s eBook, “Evernote Essentials” provides a solid guide to how this works (See the chapter called “Evernote, Email and You”) along with some other great email-related tips.

So why not just forward items to your Evernote email address? You certainly can — but I think this approach is actually easier and also has a few additional benefits:

  • FASTER/SMARTER WORKFLOW. If you use Keyboard Shortcuts with this AppleScript, you’ll have an workflow which is incredibly fast and makes it easy to stay organized! Personally, I use ⌘E to quickly send anything to Evernote. I can also tag and direct multiple items to a notebook by using a simple, fast dialog box instead of having to email them in one at a time (DEVONthink handles multiple items being forwarded by combining them into a single email). Trust me — Archiving whole folders goes much faster when you don’t have to send an email for every item!

  • PRIVACY Emailing an item into Evernote probably isn’t an option if it contains sensitive information (or should you find yourself without an internet connection). This script moves things directly — no internet connection required!

INSTALLATION

  1. On this page, click the link below “The Code” preview window which says “Click here to open it in your Script Editor”. This will open the AppleScript inside your system’s default AppleScript Editor application.
  2. You can save this script to DEVONthink’s Script Menu or into your system’s ~/Library/Scripts/ folder and launch it using the system-wide script menu from the Mac OS X menu bar. If you don’t see the system script menu, it can be activated in the Preferences of the AppleScript Editor application. (You can, of course, save the script anywhere you like and run it manually!)
  3. To use, highlight the DEVONthink items that you want to copy into Evernote and run this script file.
  4. The “User Switches” at the beginning of the script allow you to customize the way it works. Take a look to familiarize yourself with the options I’ve put in for you!

FastScripts Keyboard Shortcuts (Optional)

Do yourself a favor and download FastScripts from Red Sweater. Triggering the script from the keyboard really supercharges the process — you’ll watch items practically fly into Evernote with a few keystrokes! Here’s how you set it up:

  • Copy script or an Alias to ~/Library/Scripts/Applications/DEVONthink
  • Set up your keyboard shortcut in the FastScripts Preference menu

For my FastScripts workflow, I am using ⌘ E (as in Evernote) for my global “Send to Evernote Shortcut”. I use AppleScripts to move items from several programs into Evernote — FastScripts can detect which program I’m in and pick the appropriate script to create the note. All I have to remember is ⌘ E!

HAVING TROUBLE? FIND A BUG?

The comment thread isn’t a great way to report and diagnose individual bug reports or questions. Please click here to send a bug report directly to me.

TERMS OF USE

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

UPDATE NOTIFICATION

Follow Veritrope on Twitter to be notified of updates or fixes to this AppleScript.

The Code

(*
http://veritrope.com
DEVONthink to Evernote Exporter
VERSION 1.31
April 7, 2012

// TERMS OF USE:
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

// LIKE THIS SCRIPT?
If this AppleScript is helpful to you, please show your support here:
http://veritrope.com/support

// IMPORTANT LINKS:
-- Project Page: http://veritrope.com/code/devonthink-evernote-export
-- FastScripts (Optional): http://bit.ly/FastScripts

// INSTALLATION:  
-- You can save this script to /Library/Scripts/ and launch it using the system-wide script menu from the Mac OS X menu bar. (The script menu can be activated using the AppleScript Editor application).
-- To use, highlight the items you want to move into Evernote and run this script file;
-- The "User Switches" below allow you to customize the way this script works.

    (Optional but recommended)
    Easier Keyboard Shortcut with FastScripts
    -- Download and Install FastScripts here:
    -- http://bit.ly/FastScripts

// CHANGELOG:
1.31     FIX FOR LONG TITLES (THANK YOU, WES COWLEY!)
1.30     TEMPORARILY REMOVED GROWL
1.22     INCORPORATED CHRISTIAN GRUNENBERG'S TAG FIX
1.21    TEMP WORK-AROUND FOR TAGGING ISSUE
1.20    MISCELLANEOUS CHANGES
1.10    FILE DETECTION AND OTHER BUG FIXES
1.00    INITIAL RELEASE

*)


(*
======================================
// USER SWITCHES (YOU CAN CHANGE THESE!)
======================================
*)


--CHANGE THIS TO DESIRED DEFAULT TAG
property defaultTag : "From DEVONthink Pro"

(*
======================================
// OTHER PROPERTIES (USE CAUTION WHEN CHANGING)
======================================
*)


property theNum : "0"
property EVnotebook : ""
property thename : ""
property theNotes : ""
property theBody : ""
property theURL : ""

(*
======================================
// MAIN PROGRAM
======================================
*)


tell application id "com.devon-technologies.thinkpro2"
    set theNum to 0
    try
        if selection is not false then
            set this_selection to the selection
            set EVnotebook to my Notebook_List()
            repeat with this_item in this_selection
                set theKind to (the kind of this_item)
                set theRichText to (the rich text of this_item)
                set thename to (the name of this_item)
                --LONG TITLE FIX (WES COWLEY)
                if length of thename > 254 then set thename to (characters 1 thru 254 of thename) as string
                set theURL to (the URL of this_item)
                set theText to (the rich text of this_item)
                set theSource to (the source of this_item)
                set thePath to (the path of this_item)
                if exists tags of this_item then
                    set theTags to (the tags of this_item)
                else
                    set theTags to defaultTag
                end if
               
                -- CREATE THE NOTE FROM ITEM
                tell application "Evernote"
                    if theKind is "PDF" then
                        set n to create note from file thePath ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    else if theKind is "PDF+Text" then
                        set n to create note from file thePath ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    else if theKind is "Image" then
                        set n to create note from file thePath ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    else if theKind is "Web Archive" then
                        set n to create note with html theSource ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    else if theKind is "Bookmark" then
                        set n to create note from url theURL ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                       
                    else if theKind is "RTF" then
                        set n to create note with text theRichText ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    else if theKind is "RTFD" then
                        set n to create note with text theRichText ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    else if theKind is "Text" then
                        set n to create note with text theText ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    else if theKind is "Property List" then
                        set n to create note with text (theSource as text) ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                       
                    else if theKind is "Script" then
                        set n to create note with text theText ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    else if theKind is "HTML" then
                        set n to create note with html theSource ¬
                            title thename ¬
                            notebook EVnotebook ¬
                            tags theTags
                        set source URL of n to theURL
                       
                    end if
                end tell
            end repeat
        end if
    end try
end tell

(*
======================================
// UTILITY SUBROUTINES
======================================
*)


--SORT SUBROUTINE
on simple_sort(my_list)
    set the index_list to {}
    set the sorted_list to {}
    repeat (the number of items in my_list) times
        set the low_item to ""
        repeat with i from 1 to (number of items in my_list)
            if i is not in the index_list then
                set this_item to item i of my_list as text
                if the low_item is "" then
                    set the low_item to this_item
                    set the low_item_index to i
                else if this_item comes before the low_item then
                    set the low_item to this_item
                    set the low_item_index to i
                end if
            end if
        end repeat
        set the end of sorted_list to the low_item
        set the end of the index_list to the low_item_index
    end repeat
    return the sorted_list
end simple_sort

(*
======================================
// MAIN HANDLER SUBROUTINES
======================================
*)


--EVERNOTE NOTEBOOK SELECTION SUBROUTINE
on Notebook_List()
    tell application "Evernote"
        activate
        set listOfNotebooks to {} (*PREPARE TO GET EVERNOTE'S LIST OF NOTEBOOKS *)
        set EVNotebooks to every notebook (*GET THE NOTEBOOK LIST *)
        repeat with currentNotebook in EVNotebooks
            set currentNotebookName to (the name of currentNotebook)
            copy currentNotebookName to the end of listOfNotebooks
        end repeat
        set Folders_sorted to my simple_sort(listOfNotebooks) (*SORT THE LIST *)
        set SelNotebook to choose from list of Folders_sorted with title "Select Evernote Notebook" with prompt ¬
            "Current Evernote Notebooks" OK button name "OK" cancel button name "New Notebook" (*USER SELECTION FROM NOTEBOOK LIST *)
        if (SelNotebook is false) then (*CREATE NEW NOTEBOOK OPTION *)
            set userInput to ¬
                text returned of (display dialog "Enter New Notebook Name:" default answer "")
            set EVnotebook to userInput
        else
            set EVnotebook to item 1 of SelNotebook
        end if
    end tell
end Notebook_List

You can use these tags in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>