Last active
February 26, 2024 09:57
-
-
Save Zodiase/76b6f69666604a5e56b8d92f5a61c925 to your computer and use it in GitHub Desktop.
Folder Action: Save Discover Statements to Evernote
This file contains 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
# Expect input to be a list of file alias. | |
on run {aliasList, parameters} | |
set fileInfoList to {} | |
repeat with aliasItem in aliasList | |
set thePath to POSIX path of aliasItem | |
set theName to name of (info for aliasItem) | |
set end of fileInfoList to {thePath:thePath, theName:theName} | |
end repeat | |
return fileInfoList | |
end run |
This file contains 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
function parseFilename(filename) { | |
var result = {}; | |
var filenameBreakdown = filename.split('-'); | |
if (!(filenameBreakdown[0] === 'Discover' && filenameBreakdown[1] === 'Statement')) { | |
return null; | |
} | |
var dateString = filenameBreakdown[2]; | |
var year = parseInt(dateString.substr(0, 4), 10); | |
var month = parseInt(dateString.substr(4, 2), 10); | |
var day = parseInt(dateString.substr(6, 2), 10); | |
result.date = new Date(year, month - 1, day); | |
result.noteName = 'Discover ' + dateString; | |
result.tags = [ | |
'Discover', | |
]; | |
return result; | |
} | |
function run(fileInfoList, parameters) { | |
var EvernoteScripts = Library("Evernote"); | |
var processedFiles = []; | |
for (fileInfoItem of fileInfoList) { | |
var itemInfo = parseFilename(fileInfoItem.theName); | |
if (itemInfo === null) { | |
continue; | |
} | |
fileInfoItem.isSaved = EvernoteScripts.saveStatementToEvernote( | |
itemInfo.noteName, | |
fileInfoItem.thePath, | |
itemInfo.tags, | |
itemInfo.date | |
); | |
processedFiles.push(fileInfoItem); | |
} | |
return processedFiles; | |
} |
This file contains 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
on run {fileInfoList, parameters} | |
set theFiles to {} | |
repeat with fileInfoItem in fileInfoList | |
set end of theFiles to POSIX file (thePath of fileInfoItem) as alias | |
end repeat | |
return theFiles | |
end run |
This file contains 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
# theTitle should be a string. | |
# theStatementFilePath should be a POSIX path. | |
# theTags should be an array. | |
# theDate should be a Date object. | |
to saveStatementToEvernote(theTitle, theStatementFilePath, theTags, theDate) | |
set TargetNoteBookName to "Finance" | |
set theStatementFile to POSIX file theStatementFilePath | |
tell application "Evernote" | |
set targetNoteBook to missing value | |
set targetNote to missing value | |
repeat until isSynchronizing is false | |
-- wait until sync is done | |
end repeat | |
-- create the target notebook if not found | |
if (not (notebook named TargetNoteBookName exists)) then | |
make notebook with properties {name:TargetNoteBookName} | |
end if | |
set targetNoteBook to notebook named TargetNoteBookName | |
set notesWithSameTitle to find notes "notebook:\"" & TargetNoteBookName & "\" \"" & theTitle & "\"" | |
if (length of notesWithSameTitle is not 0) then | |
return false | |
end if | |
set targetNote to create note from file theStatementFile title theTitle notebook targetNoteBook tags theTags created theDate | |
assign tag "Bank Statement" to targetNote | |
synchronize | |
return true | |
end tell | |
end saveStatementToEvernote |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn’t know Evernote had a scripting language