Last active
August 11, 2018 16:30
-
-
Save mbierman/1ef3f255ce1ca50bb2fffbf99d715704 to your computer and use it in GitHub Desktop.
Ever want a 'Find and Replace' for Evernote? Here's an Aplescript for doing that on a Mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (* | |
| Find and replace based on | |
| Evernote Note Folder | |
| Version 1.02 | |
| 2018/03/15 | |
| SCRIPT INFORMATION | |
| Retrieves the note's Mac folder from the database | |
| TERMS OF USE: | |
| CHANGELOG: | |
| RECOMMENDED INSTALLATION AND USAGE INSTRUCTIONS: | |
| - the database folder is hard-coded for variable targetDatabaseFolder and will have to be adjusted for the user | |
| *) | |
| global aNote | |
| global targetFilepath | |
| set databaseFolder to "/Users/bierman/Library/Containers/com.evernote.Evernote/Data/Library/Application Support/com.evernote.Evernote/accounts/www.evernote.com/201447/" | |
| set databaseFile to databaseFolder & "localNoteStore/LocalNoteStore.sqlite" | |
| set noteUID to getNoteUID() | |
| set localFolder to databaseFolder & "content/" & getLocalFolder(databaseFile, noteUID) | |
| -- tell application "Finder" to open folder localFolder as POSIX file | |
| ------------------------------------------------------------GetvNote Guid | |
| ------------------------------------------------------------- Parse from link | |
| on getNoteUID() | |
| tell application "Evernote" | |
| set theSelection to get selection | |
| set theNote to item 1 of theSelection | |
| set theLink to note link of theNote | |
| set _sel to selection | |
| -- Gets the Note(s) Selected in Evernote | |
| if _sel ≠ {} then | |
| set aNote to first item of _sel | |
| end if | |
| end tell | |
| set AppleScript's text item delimiters to "/" | |
| set parsedList to text items of theLink | |
| set noteUID to item 7 of parsedList | |
| return noteUID | |
| end getNoteUID | |
| ------------------------ Get Local Folder | |
| ------------------------ Retrive from sqlite database | |
| on getLocalFolder(databaseFile, noteUID) | |
| set sqlText to "SELECT ZLOCALUUID FROM ZenNote where ZGUID = '" & noteUID & "';" | |
| set localFolder to text items of (do shell script "sqlite3 " & quote & databaseFile & quote & " " & quote & sqlText & quote) | |
| end getLocalFolder | |
| set targetFilepath to POSIX file (localFolder & "/content.enml") | |
| tell application "Evernote" | |
| open note window with aNote | |
| tell application "System Events" | |
| tell process "Evernote" to keystroke "s" using {command down, control down} | |
| tell process "Evernote" to keystroke "s" using {command down} | |
| end tell | |
| end tell | |
| -- do shell script "open -a TextEdit targetFilepath" | |
| -- display dialog targetFilepath | |
| tell application "TextEdit" | |
| activate | |
| open targetFilepath | |
| tell (windows whose id is not (get id of front window) and visible is true) | |
| set miniaturized to true | |
| end tell | |
| set bounds of front window to {279, 111, 1180, 719} | |
| tell application "System Events" | |
| -- open the Replace dialog | |
| tell process "TextEdit" to keystroke "f" using {option down, command down} | |
| -- place cursor in the "Find" portion | |
| tell process "TextEdit" to keystroke "f" using {command down} | |
| -- paste the text from the clipboard . This is meant to be used if you copied what you wanted changed from Evernote before running this script. | |
| tell process "TextEdit" to keystroke "v" using {command down} | |
| tell process "TextEdit" to keystroke tab | |
| tell process "TextEdit" to keystroke tab | |
| tell process "TextEdit" to keystroke tab | |
| tell process "TextEdit" to keystroke tab | |
| end tell | |
| end tell | |
| repeat | |
| if application "TextEdit" is not running then exit repeat | |
| delay 1 | |
| end repeat | |
| tell application "System Events" to set frontmost of process "Evernote" to true | |
| tell application "Evernote" | |
| close window 1 | |
| open note window with aNote | |
| tell application "System Events" | |
| tell process "Evernote" to keystroke "l" using {command down} | |
| delay 0.25 | |
| tell process "Evernote" to keystroke tab | |
| delay 0.25 | |
| tell process "Evernote" to key code "49" | |
| delay 0.25 | |
| tell process "Evernote" to key code "51" | |
| delay 0.25 | |
| tell process "Evernote" to keystroke "s" using {command down, control down} | |
| end tell | |
| end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment