forked from lemonmade/evernote-extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvernote Image Extractor.applescript
147 lines (127 loc) · 5.25 KB
/
Evernote Image Extractor.applescript
1
(* EVERNOTE IMAGE EXTRACTOR.SCPT By Chris Sauve of [pxldot](http://pxldot.com). See README for details.*)tell application "Evernote.app" set typesToGet to button returned of (display dialog "Would you like to export images, PDF documents, or both?" buttons {"Export Images", "Export PDFs", "Export Both"} default button 3) set notebookList to every notebook of it set notebookNameList to {"Every Notebook"} & name of every notebook of it set chosenNotebooks to {} set chosenNotebookNames to choose from list notebookNameList with prompt "Select which notebooks from which you would like to export note images:" with multiple selections allowed if chosenNotebookNames is false then return try set theFolder to (choose folder with prompt "Where would you like to save the exported images? Note that the script will create subfolders for each notebook you export.") as text on error number -128 return end try repeat with i from 1 to (length of chosenNotebookNames) if item i of chosenNotebookNames is "Every Notebook" then set chosenNotebooks to notebookList exit repeat end if repeat with j from 1 to (length of notebookNameList) if item i of chosenNotebookNames contains item j of notebookNameList then set end of chosenNotebooks to item (j - 1) of notebookList end if end repeat end repeat repeat with theNotebook in chosenNotebooks set theName to name of theNotebook tell application "Finder" try copy theFolder to temp make new folder at theFolder with properties {name:theName} set theFolder to result as text end try end tell tell theNotebook set noteList to every note of it if length of noteList is not 0 then set duplicateFileNameTally to {} repeat with theNote in noteList set noteName to title of theNote set attachmentList to every attachment of theNote set imageAttachmentList to {} set pdfAttachmentList to {} repeat with i from 1 to (length of attachmentList) set theType to mime of item i of attachmentList if (typesToGet is not "Export PDFs") and (theType starts with "image") then set the end of imageAttachmentList to item i of attachmentList else if (typesToGet is not "Export Images") and (theType ends with "pdf") then set the end of pdfAttachmentList to item i of attachmentList end if end repeat if (length of imageAttachmentList) > 0 then repeat with i from 1 to (length of imageAttachmentList) set theAttachment to item i of imageAttachmentList set my text item delimiters to "image/" set theType to every text item of theType set my text item delimiters to "" set theType to theType as string set desiredPath to (theFolder & noteName & "." & theType) tell application "Finder" if desiredPath exists then if (count of duplicateFileNameTally) is 0 then set end of duplicateFileNameTally to {thePath:desiredPath, theCount:2} set desiredPath to theFolder & noteName & " 1." & theType else set recordFound to false repeat with i from 1 to (count of duplicateFileNameTally) tell item i of duplicateFileNameTally if its thePath contains desiredPath then set desiredPath to theFolder & noteName & " " & (theCount of it) & "." & theType set theCount of it to ((theCount of it) + 1) set recordFound to true end if end tell end repeat if not recordFound then set end of duplicateFileNameTally to {thePath:desiredPath, theCount:2} set desiredPath to theFolder & noteName & " 1." & theType end if end if end if end tell try write attachment to desiredPath end try end repeat end if if (length of pdfAttachmentList) > 0 then repeat with i from 1 to (length of pdfAttachmentList) set theAttachment to item i of pdfAttachmentList set theType to "pdf" set desiredPath to (theFolder & noteName & "." & theType) tell application "Finder" if desiredPath exists then if (count of duplicateFileNameTally) is 0 then set end of duplicateFileNameTally to {thePath:desiredPath, theCount:2} set desiredPath to theFolder & noteName & " 1." & theType else set recordFound to false repeat with i from 1 to (count of duplicateFileNameTally) tell item i of duplicateFileNameTally if its thePath contains desiredPath then set desiredPath to theFolder & noteName & " " & (theCount of it) & "." & theType set theCount of it to ((theCount of it) + 1) set recordFound to true end if end tell end repeat if not recordFound then set end of duplicateFileNameTally to {thePath:desiredPath, theCount:2} set desiredPath to theFolder & noteName & " 1." & theType end if end if end if end tell write theAttachment to desiredPath end repeat end if end repeat end if end tell set theFolder to temp end repeatend tell