Skip to content

Instantly share code, notes, and snippets.

Created December 10, 2012 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4251290 to your computer and use it in GitHub Desktop.
Save anonymous/4251290 to your computer and use it in GitHub Desktop.
EverNote import into DevonThink with tags
-- Import EverNote .enex files
-- Created by Christian Grunenberg on Mar Wed 25 2009.
-- Copyright (c) 2009. All rights reserved.
tell application id "com.devon-technologies.thinkpro2"
try
if not (exists current database) then error "No database is open."
set theFile to choose file with prompt "Choose an EverNote .enex file:" without invisibles, multiple selections allowed and showing package contents
set theGroup to create location "/EverNote"
set theNum to 0
tell application "System Events"
set theXMLData to XML file (POSIX path of theFile)
set theNotes to XML elements of (XML element 1 of theXMLData)
repeat with theNote in theNotes
try
set theTitle to (value of XML element named "title" of theNote) as string
set theContent to (value of XML element named "content" of theNote) as string
try
set theAttributes to XML element named "note-attributes" of theNote
set theSourceURL to (value of XML element named "source-url" of theAttributes) as string
on error
set theSourceURL to ""
end try
set theContent to my replaceString(theContent, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "")
set theContent to my replaceString(theContent, "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml.dtd\">", "")
set theContent to my replaceString(theContent, "<en-note>", "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><body>")
set theContent to my replaceString(theContent, "</en-note>", "</body></html>")
try
set theTags to (value of every XML element of theNote whose name = "tag")
on error
set theTags to ""
end try
tell application id "com.devon-technologies.thinkpro2" to create record with {name:theTitle, type:html, URL:theSourceURL, source:theContent, tags:theTags} in theGroup
set theNum to theNum + 1
end try
end repeat
end tell
error "Added " & (theNum as string) & " notes."
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell
on replaceString(theString, theOriginalString, theNewString)
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theOriginalString}
set theStringParts to text items of theString
if (count of theStringParts) is greater than 1 then
set theString to text item 1 of theStringParts as string
repeat with eachPart in items 2 thru -1 of theStringParts
set theString to theString & theNewString & eachPart as string
end repeat
end if
set AppleScript's text item delimiters to od
return theString
end replaceString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment