19
May
Change Log:
- 1.00 (MAY 12, 2009) INITIAL RELEASE OF SCRIPT
Okay AppleScripters — here’s the code… Dive in, check it out, and please tell me what you think in the comment thread below!
(*
http://veritrope.com
Evernote HTML Exporter
Version 1.0
May 12, 2009
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/tips/evernote-HTML-export
EXTRA SPECIAL THANKS TO PAUL AT ENTROPYTHEBLOG.COM
FOR HIS HELP IN TROUBLESHOOTING THE WEBARCHIVER!
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/Evernote
--Set up your keyboard shortcut
CHANGELOG:
1.00 INITIAL RELEASE
*)
property CleanTitle : ""
property theNum : "0"
(* 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 ¬
"Evernote to HTML" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Evernote"
end tell
end if
(*MAIN PROGRAM *)
set myPath to (path to home folder)
set EVPath to ("" & myPath & "Library:Application Support:Evernote:data:40145:content:p") as string
tell application "Evernote"
activate
try
(* EVERNOTE NOTEBOOK SELECTION SUBROUTINE *)
set listOfNotebooks to {}
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
(*SORT THE FOLDER LIST *)
set Folders_sorted to my simple_sort(listOfNotebooks)
(*USER SELECTION FROM NOTEBOOK LIST *)
set SelNotebook to choose from list of Folders_sorted with title "Select Evernote Notebook" with prompt ¬
"Current Evernote Notebooks" OK button name "OK"
set EVnotebook to item 1 of SelNotebook
set listofNotes to {} (*PREPARE TO GET EVERNOTE'S LIST OF NOTES *)
set allNotes to every note in notebook EVnotebook
repeat with currentNote in allNotes
set currentNoteName to (the title of currentNote)
copy currentNoteName to the end of listofNotes
end repeat
(*SORT THE NOTEBOOK LIST *)
set Notes_sorted to my simple_sort(listofNotes)
(*PICK THE NOTES FROM THE LIST *)
set SelNotes to ¬
choose from list of Notes_sorted with title ¬
"List of Notes" OK button name "Export Notes" cancel button name "Close Window" with multiple selections allowed
-- NOTE: ALL UNTITLED NOTES SHOW UP AS SINGLE "UNTITLED" ENTRY
if (SelNotes is not false) then
(*PICK EXPORT DESTINATION*)
set SaveLoc to choose folder with prompt "Choose The Destination Folder or Volume:" default location (path to desktop folder)
(*DO THE CONVERSION*)
my ENEXExport(EVnotebook, SelNotes, SaveLoc, EVPath)
if "GrowlHelperApp" is in processnames then -- GROWL SUCCESS
tell application "GrowlHelperApp"
notify with name ¬
"Success Notification" title ¬
"Successful Export to HTML!" description ¬
"Number of Notes Exported: " & theNum application name "Evernote to HTML"
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 ¬
"Export Failure" description ¬
"No notes selected!" application name "Evernote to HTML"
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 "Export Failed due to the following error: " & errText & return & return & "Note Name: " & CleanTitle ¬
application name "Evernote to HTML"
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 *)
on ENEXExport(EVnotebook, SelNotes, SaveLoc, EVPath)
(*FIND FOLDER FOR NOTE*)
tell application "Evernote"
set theNum to 0
repeat with SelNote in SelNotes
set noteToExport to (find notes "notebook:"" & EVnotebook & "" intitle:"" & SelNote & """)
set NoteID to (local id of item 1 of noteToExport)
set FolderLoc to my extractBetween(NoteID, "/p", """)
(*PREPARE HTML FOLDER *)
tell application "Finder"
activate
set GetFolder to (EVPath & FolderLoc & ":") as alias
set SingQuote to "-e s/'//g"
set CleanTitle to do shell script ("echo " & quoted form of SelNote & " | sed -e 's/:/ /g' -e 's/"//g' -e 's/—/ /g' " & (quoted form of SingQuote)) --CLEAN OUT COLONS FOR FILE PATH (SOUNDS GROSSER THAN IT IS)
set ExportFolder to ¬
(make new folder at SaveLoc with properties {name:CleanTitle})
set notreco to (every item in GetFolder whose ¬
kind is not "Document")
(*COPY CONTENTS TO HTML EXPORT FOLDER *)
duplicate notreco to ExportFolder
set WebArchive to POSIX path of ((path to me as Unicode text) & "Contents:Resources:webarchiver")
set ArchiveInput to POSIX path of ((ExportFolder as Unicode text) & "content.html")
set ArchiveOutput to POSIX path of ((SaveLoc as Unicode text) & CleanTitle & ".webarchive")
set Exec to "'" & WebArchive & "' -url '" & ArchiveInput & "' -output '" & ArchiveOutput & "'"
do shell script Exec
end tell
set theNum to theNum + 1
end repeat
end tell
end ENEXExport
--REPLACE SUBROUTINE
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
--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
--EXTRACT SUBROUTINE
on extractBetween(SearchText, startText, endText)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to startText
set endItems to text of text item -1 of SearchText
set AppleScript's text item delimiters to endText
set beginningToEnd to text of text item 1 of endItems
set AppleScript's text item delimiters to tid
return beginningToEnd
end extractBetween
http://veritrope.com
Evernote HTML Exporter
Version 1.0
May 12, 2009
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/tips/evernote-HTML-export
EXTRA SPECIAL THANKS TO PAUL AT ENTROPYTHEBLOG.COM
FOR HIS HELP IN TROUBLESHOOTING THE WEBARCHIVER!
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/Evernote
--Set up your keyboard shortcut
CHANGELOG:
1.00 INITIAL RELEASE
*)
property CleanTitle : ""
property theNum : "0"
(* 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 ¬
"Evernote to HTML" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Evernote"
end tell
end if
(*MAIN PROGRAM *)
set myPath to (path to home folder)
set EVPath to ("" & myPath & "Library:Application Support:Evernote:data:40145:content:p") as string
tell application "Evernote"
activate
try
(* EVERNOTE NOTEBOOK SELECTION SUBROUTINE *)
set listOfNotebooks to {}
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
(*SORT THE FOLDER LIST *)
set Folders_sorted to my simple_sort(listOfNotebooks)
(*USER SELECTION FROM NOTEBOOK LIST *)
set SelNotebook to choose from list of Folders_sorted with title "Select Evernote Notebook" with prompt ¬
"Current Evernote Notebooks" OK button name "OK"
set EVnotebook to item 1 of SelNotebook
set listofNotes to {} (*PREPARE TO GET EVERNOTE'S LIST OF NOTES *)
set allNotes to every note in notebook EVnotebook
repeat with currentNote in allNotes
set currentNoteName to (the title of currentNote)
copy currentNoteName to the end of listofNotes
end repeat
(*SORT THE NOTEBOOK LIST *)
set Notes_sorted to my simple_sort(listofNotes)
(*PICK THE NOTES FROM THE LIST *)
set SelNotes to ¬
choose from list of Notes_sorted with title ¬
"List of Notes" OK button name "Export Notes" cancel button name "Close Window" with multiple selections allowed
-- NOTE: ALL UNTITLED NOTES SHOW UP AS SINGLE "UNTITLED" ENTRY
if (SelNotes is not false) then
(*PICK EXPORT DESTINATION*)
set SaveLoc to choose folder with prompt "Choose The Destination Folder or Volume:" default location (path to desktop folder)
(*DO THE CONVERSION*)
my ENEXExport(EVnotebook, SelNotes, SaveLoc, EVPath)
if "GrowlHelperApp" is in processnames then -- GROWL SUCCESS
tell application "GrowlHelperApp"
notify with name ¬
"Success Notification" title ¬
"Successful Export to HTML!" description ¬
"Number of Notes Exported: " & theNum application name "Evernote to HTML"
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 ¬
"Export Failure" description ¬
"No notes selected!" application name "Evernote to HTML"
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 "Export Failed due to the following error: " & errText & return & return & "Note Name: " & CleanTitle ¬
application name "Evernote to HTML"
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 *)
on ENEXExport(EVnotebook, SelNotes, SaveLoc, EVPath)
(*FIND FOLDER FOR NOTE*)
tell application "Evernote"
set theNum to 0
repeat with SelNote in SelNotes
set noteToExport to (find notes "notebook:"" & EVnotebook & "" intitle:"" & SelNote & """)
set NoteID to (local id of item 1 of noteToExport)
set FolderLoc to my extractBetween(NoteID, "/p", """)
(*PREPARE HTML FOLDER *)
tell application "Finder"
activate
set GetFolder to (EVPath & FolderLoc & ":") as alias
set SingQuote to "-e s/'//g"
set CleanTitle to do shell script ("echo " & quoted form of SelNote & " | sed -e 's/:/ /g' -e 's/"//g' -e 's/—/ /g' " & (quoted form of SingQuote)) --CLEAN OUT COLONS FOR FILE PATH (SOUNDS GROSSER THAN IT IS)
set ExportFolder to ¬
(make new folder at SaveLoc with properties {name:CleanTitle})
set notreco to (every item in GetFolder whose ¬
kind is not "Document")
(*COPY CONTENTS TO HTML EXPORT FOLDER *)
duplicate notreco to ExportFolder
set WebArchive to POSIX path of ((path to me as Unicode text) & "Contents:Resources:webarchiver")
set ArchiveInput to POSIX path of ((ExportFolder as Unicode text) & "content.html")
set ArchiveOutput to POSIX path of ((SaveLoc as Unicode text) & CleanTitle & ".webarchive")
set Exec to "'" & WebArchive & "' -url '" & ArchiveInput & "' -output '" & ArchiveOutput & "'"
do shell script Exec
end tell
set theNum to theNum + 1
end repeat
end tell
end ENEXExport
--REPLACE SUBROUTINE
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
--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
--EXTRACT SUBROUTINE
on extractBetween(SearchText, startText, endText)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to startText
set endItems to text of text item -1 of SearchText
set AppleScript's text item delimiters to endText
set beginningToEnd to text of text item 1 of endItems
set AppleScript's text item delimiters to tid
return beginningToEnd
end extractBetween
Did this script help you out? Feel free to make a donation!
Interested in what other scripts are available for Evernote?
Click here to see the latest list!
Page 1 Page 2




Trackbacks/Pingbacks