21
May
DEVONthink to Evernote Exporter Applescript
Tags: Apple, Applescript, DEVONthink, Evernote, tutorial
Change Log:
- 1.22 (March 3, 2010) TAGGING ISSUE RESOLVED
- 1.21 (February 25, 2010) TEMPORARY WORK-AROUND FOR TAGGING ISSUE
- 1.20 (January 31, 2010) BUG FIX — HTML FILE IMPORT
- 1.10 (May 22, 2009) FILE DETECTION AND OTHER BUG FIXES
- 1.00 (May 12, 2009) INITIAL RELEASE OF SCRIPT
Okay all you Applescript Ninjas — here’s the code… Dive in, check it out, and tell me how to make it better in the comment thread below!
(*
http://veritrope.com
DEVONthink to Evernote Exporter
Version 1.22
March 3, 2010
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/tips/devonthink-evernote-export
Installation: Just double-click on the script!
FastScripts Installation (Optional, but recommended):
--Download and Install FastScripts from http://www.red-sweater.com/fastscripts/index.html
--Copy script or an Alias to ~/Library/Scripts/Applications/DEVONthink
--Set up your keyboard shortcut
CHANGELOG:
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
*)
property theNum : "0"
property EVnotebook : ""
property thename : ""
property theNotes : ""
property theBody : ""
property theURL : ""
property defaultTag : "From DEVONthink Pro"
(* CHECK FOR GROWL *)
tell application "System Events"
set processnames to name of every process
end tell
if "GrowlHelperApp" is in processnames then
tell application "GrowlHelperApp"
set the allNotificationsList to {"Success Notification", "Failure Notification"}
set the enabledNotificationsList to {"Success Notification", "Failure Notification"}
register as application ¬
"Devon to Evernote" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Evernote"
end tell
end if
(*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)
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
tell application "Evernote" -- CREATE THE NOTE FROM ITEM
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
set theNum to theNum + 1
end repeat
if "GrowlHelperApp" is in processnames then
tell application "GrowlHelperApp" -- GROWL SUCCESS
notify with name ¬
"Success Notification" title ¬
"Import Success" description "Successfully exported " & theNum & ¬
" Notes to the " & EVnotebook & " notebook in Evernote" application name "Devon to Evernote"
end tell
end if
else
if "GrowlHelperApp" is in processnames then
tell application "GrowlHelperApp" -- GROWL FAILURE FOR NO SELECTION
notify with name ¬
"Failure Notification" title ¬
"Import Failure" description ¬
"No headline or tab selected!" application name "Devon to Evernote"
end tell
else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR NO SELECTION
display dialog "No headline or tab selected!" with icon 0
end if
end if
(* ERROR HANDLING *)
on error errText number errNum
if "GrowlHelperApp" is in processnames then
tell application "GrowlHelperApp" -- GROWL FAILURE FOR ERROR
notify with name ¬
"Failure Notification" title ¬
"Import Failure" description "Failed to export " & return & thename & ¬
"\" due to the following error: " & return & errText ¬
application name "Devon to Evernote"
end tell
else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR ERROR
display dialog "Item Failed to Import: " & errNum & return & errText with icon 0
end if
end try
end tell
(* 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
--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
http://veritrope.com
DEVONthink to Evernote Exporter
Version 1.22
March 3, 2010
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/tips/devonthink-evernote-export
Installation: Just double-click on the script!
FastScripts Installation (Optional, but recommended):
--Download and Install FastScripts from http://www.red-sweater.com/fastscripts/index.html
--Copy script or an Alias to ~/Library/Scripts/Applications/DEVONthink
--Set up your keyboard shortcut
CHANGELOG:
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
*)
property theNum : "0"
property EVnotebook : ""
property thename : ""
property theNotes : ""
property theBody : ""
property theURL : ""
property defaultTag : "From DEVONthink Pro"
(* CHECK FOR GROWL *)
tell application "System Events"
set processnames to name of every process
end tell
if "GrowlHelperApp" is in processnames then
tell application "GrowlHelperApp"
set the allNotificationsList to {"Success Notification", "Failure Notification"}
set the enabledNotificationsList to {"Success Notification", "Failure Notification"}
register as application ¬
"Devon to Evernote" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Evernote"
end tell
end if
(*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)
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
tell application "Evernote" -- CREATE THE NOTE FROM ITEM
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
set theNum to theNum + 1
end repeat
if "GrowlHelperApp" is in processnames then
tell application "GrowlHelperApp" -- GROWL SUCCESS
notify with name ¬
"Success Notification" title ¬
"Import Success" description "Successfully exported " & theNum & ¬
" Notes to the " & EVnotebook & " notebook in Evernote" application name "Devon to Evernote"
end tell
end if
else
if "GrowlHelperApp" is in processnames then
tell application "GrowlHelperApp" -- GROWL FAILURE FOR NO SELECTION
notify with name ¬
"Failure Notification" title ¬
"Import Failure" description ¬
"No headline or tab selected!" application name "Devon to Evernote"
end tell
else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR NO SELECTION
display dialog "No headline or tab selected!" with icon 0
end if
end if
(* ERROR HANDLING *)
on error errText number errNum
if "GrowlHelperApp" is in processnames then
tell application "GrowlHelperApp" -- GROWL FAILURE FOR ERROR
notify with name ¬
"Failure Notification" title ¬
"Import Failure" description "Failed to export " & return & thename & ¬
"\" due to the following error: " & return & errText ¬
application name "Devon to Evernote"
end tell
else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR ERROR
display dialog "Item Failed to Import: " & errNum & return & errText with icon 0
end if
end try
end tell
(* 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
--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
Don’t Just Be A Taker… Please “Support The Cause” With Your Donations, Comments, And Retweets!
Found a bug in the script?
Click Here To Submit Your Bug Report!
Is there a script to move the files in the other direction?
Click here for a script that exports from Evernote to DEVONthink
Interested in what other scripts are available for Evernote?
Click here to see the latest list!
DEVONthink to Evernote Exporter ApplescriptPages: 1 2









29 Responses to “DEVONthink to Evernote Exporter Applescript”
Anyway to get this to work in devonthink 1.9?
Not working with this version..
I haven’t tested this out, but you might try changing one line of the script in Script Editor to see if that gets you up and running:
Open the Script in Script Editor and find the first line under the (* MAIN PROGRAM *) comment;
Replace the line that says tell application id “com.devon-technologies.thinkpro2″ with tell application “DEVONthink Pro”
Compile and save the script
Let me know if that works for you — if it does, I may include that in the next revision of the script (assuming that it doesn’t break anything in 2.0!)
Kind Regards,
Justin
Justin, thanks for the tip. I however solved it just by upgrading. Now that my stuff is out of Devonthink, i am fully into evernote.
Actually, i only had devonthink personal, and i dont think the personal version has script support.
Is the link to the DevonThink –> Evernote utility still active? I could download other scripts but not thie one.
Thx,
Scott
Hi Scott,
Thanks for letting me know about the problem with the link!
It should be fixed — hope you enjoy the script and let me know how you like it (and the others).
-Justin
Thx Justin – all fixed!
These scripts are great, btw – thx for everything!
I wanted to try the change that Justin mentioned above to use this script with my copy of DEVONthink Pro 1.5.4, but I can’t get into the script (it’s run only) to make the change. And I tried pasting the code above directly into AppleScript Editor, but I got syntax errors.
Help! I really want this to work, but I am just clueless. Thanks!
Robyn,
I quickly compiled a version for you to try — download link is under the original link.
You’re going to have to be my “guinea pig” on this one, as I don’t have DEVONthink 1.x anymore…. try it out and let me know your results!
Hi Justin,
Thanks for the fast response. I think it almost worked, but then I got the following dialogue box:
“Item failed to import: -1728 DEVONthink Pro got an error: Can’t get of content id 24143 of database 1.”
I guess I could upgrade to the DEVONthink 2.0 beta, but I am unsure whether I want to ultimately pay for the upgrade, hence the migration to Evernote — or at least that was my thinking…
I look forward to hearing back from you, and again thanks for the fast turnaround — awesome!!!
Also, does the script need to notate that one is using DEVONthink Pro vs DEVONthink Personal? That just popped in my head as well as I downloaded the Pro 2.0 beta…thanks!
HI Robyn,
Happy to (try to) help!
The script assumes that you’re running DEVONthink Pro as the Personal Edition is not fully supported for AppleScripting.
Not sure why you’re receiving that error message and, since I don’t have DEVONthink 1.x on my system anymore, it’s not really possible for me to test. Can you tell me what kind of note you were trying to export? (i.e., a PDF, a text file, etc.).
Since you’ve probably already downloaded and installed the DEVONthink beta by now, why don’t you use the original DEVONthink 2 to Evernote script to export into Evernote while you evaluate the new version? I believe that DEVONthink leaves the original version 1.x database intact when it converts it to the 2.0 compatible version — although, if you haven’t upgraded yet, you should probably back it up just in case my memory is incorrect!
Yes, it does work with the beta, which is pretty cool in and of itself
Thanks again!
“Source code and download link on the next page!”
The next page? Where is the next page? I can’t see any hint and the text above is not a link. Please clarify.
Thank you
Never mind. Found it. Thanks.
In case anyone else has the same question:

Hi Justin,
thanks for the script, I’ve been using it for a while and it works great for PDF and RTF notes; the problem is that it doesn’t seem to work with HTML notes, I get a Growl notification saying that the export has been successful but the note does not show up in Evernote. Is it a known limitation? thanks for your help. Lucas.
Lucas,
It was a bug…. (I can’t believe that no one else reported this one!)
Should be fixed in version 1.2 of the script — please download it and let me know if it works for you.
that was quick!, tried it and it works!, one small detail though, if you copy the source directly you have an extra “(*” in line 01, and the script won’t compile.
thanks a lot, this is really helpful.
Source Fixed!
… and I’m nominating you for “Bug Finder of the Month!”!
(This is a purely ceremonial honor, sadly.)
Twitter Comment
To export your DevonThink items to EverNote easily, use this AppleScript! [link to post]
– Posted using Chat Catcher
Devonthnk to Evernote not working for me. I get a notification – The variable theTags is not defined. Any way round this, thanks?
Ah — the joys of everything not working when a beta goes final..
I’ve worked up a quick patch for some tagging-related anomalies that were causing your error (see notes on Page 1). It is Version 1.21 of the script and is now available for download.
Next stop — getting in touch with DEVON to let them know about it!
Justin. Huge thanks and respect. Using the new (final) release of DEVONthink Pro Office 2.0 and the latest version of Evernote for Mac I can now send documents both ways. The two coolest notetaking/archiving applications are now officially talking to each other. Excellent work!
FYI — Christian Grunenberg at DEVONtechnologies provided some code that will restore full tagging support, and I’ve updated the script to version 1.22 to incorporate his suggestion.
For any other DEVONthink scripters out there having tag-related problems, he also says the following:
Let me know how it works for you!
You are my hero. I’ve been trying to find a way to transport over 20,000 files from DevonThink Pro 2.0 to EverNote and had almost given up. My only problem, however, is that I have a lot of formatted text (italics, colored fonts, etc) that are now gone. Is there any way to move the files and keep all formatting intact?
Thanks!
Hi Mark,
Glad that the script was helpful!
I am actually looking at ways of doing just that (Some of it is a function of how Evernote processes the text, however…).
If it’s possible, I’ll make it happen!
That’s great, Justin. I look forward to your updates. Thanks again for your help!
Justin,
I know you’re looking into ways of making the formatting work out, but if I were to hire you to write me a script to do just that, how much would it cost? I’m to the point that I would pay someone for a script that would make it possible to copy my DevonThink notes over to Evernote, but I want ALL formatting to be identical. I actually love both DevonThink Pro and Evernote, I just want to be able to have my notes on both programs and have them look the same. Is this something you would consider doing for me?
Thanks,
Mark
**I DO** create custom AppleScripts and workflows for my clients and would be happy to tailor any script to you and to how you work! You can read the short description of how that works and get in touch so we can coordinate the details.
Trackbacks/Pingbacks