Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Folder Action: Save Discover Statements to Evernote
# 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
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); = new Date(year, month - 1, day);
result.noteName = 'Discover ' + dateString;
result.tags = [
return result;
function run(fileInfoList, parameters) {
var EvernoteScripts = Library("Evernote");
var processedFiles = [];
for (fileInfoItem of fileInfoList) {
var itemInfo = parseFilename(fileInfoItem.theName);
if (itemInfo === null) {
fileInfoItem.isSaved = EvernoteScripts.saveStatementToEvernote(
return processedFiles;
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
# 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
return true
end tell
end saveStatementToEvernote

This comment has been minimized.

Copy link

@anthonybrown anthonybrown commented Dec 17, 2018

I didn’t know Evernote had a scripting language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.