Automatically Generate Daily Notes in Evernote

Q: I like to keep daily journal entries in Evernote, but it is tedious to keep having to create a new note and type in the date every day. Is there an automatic way for these to be created with the proper title?

A: Yes there is, using a mixture of AppleScript and launchd, you can generate a new note in Evernote every single day.

The AppleScript

First, we will write an AppleScript to create a blank note titled in the format of "Journal MM/DD/YY" and add it to the notebook named "Journal."

tell application id "com.evernote.evernote"
    delay 20 -- Wait for internet connection if just waking up

    set formattedDate to do shell script "date '+%m/%d/%y'"
    set journalNoteTitle to "Journal " & (formattedDate)

    -- Check that the note doesn't already exist
    if ((count of (find notes "intitle:" & journalNoteTitle)) is 0) then
        create note with text "" title journalNoteTitle notebook "Journal"
        synchronize
    end if
end tell

Open this script in AppleScript Editor and run it to make sure it works like you want it to. Save it to a permanent location, because the next part needs to know where the script is to run it every day. I have it saved to ~/Applications/Scripts/Evernote-JournalEntry.scpt.

The launchd plist

We have a script to create a new journal entry, now we just need a way for it to run automatically every day. The launchd service can do this for us. Launchd is the part of Mac OS X responsible for launching programs at specified times. You can create very intricate schedules if you want, but we will just keep it simple and have it run once a day, every day.

When you start up your computer, launchd looks in the ~/Library/LaunchAgents folder for plist files that describe a schedule to run a task. Here is the plist I use:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.briankoponen.evernote_journal</string>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>brian</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>/Users/brian/Applications/Scripts/Evernote-JournalEntry.scpt</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>6</integer>
        <key>Minute</key>
        <integer>15</integer>
    </dict>
    <key>LimitLoadToSessionType</key>
    <string>Aqua</string>
</dict>
</plist>

Make sure to put your username in the file and the full path to the script. This tells launchd to run the Evernote-JournalEntry.scpt file every day at 6:15AM. Launchd will run any task that was scheduled to run while the computer was asleep as soon as it wakes up. By setting RunAtLoad to true, the script will also run every time the computer starts up, so if you shutdown at night, it will run when you turn your computer on in the morning.

Create this file and save it to ~/Library/LaunchAgents/com.briankoponen.evernote_journal.plist. It is customary to name these files in this reverse domain style to prevent naming collisions between launchd tasks. If you do change the name of the file, make sure to change the label name in the file itself as well.

When you restart, launchd will automatically load this file, or you can load it manually in the terminal using this command:

$ launchctl load ~/Library/LaunchAgents/com.briankoponen.evernote_journal.plist


Bonus: Easy access to your new note.

In Evernote itself you can create a saved search for easy access to your daily journal entry.

  • Click on the search field, at the bottom of the popup panel click on "Add Search Option" and choose "Notebook."
  • Select your Journal notebook and click "Add." 
  • Click "Add Search Option" again and choose "Created." Select "since" and "yesterday" and click "Add."
  • Go to Edit > Find > Save Search and name it something like "Daily Journal." 
  • Finally, click once again on the search field and you will see your newly created saved search. Drag this over to the "Shortcuts" section in the sidebar for easy access later.

These shortcuts sync across all your devices. I find this trick especially useful for the mobile app because the Shortcuts are very easily accessible.

References:

For information on working with dates in Applescript: http://macscripter.net/viewtopic.php?id=24737

For information on launchd: http://nathangrigg.net/2012/07/schedule-jobs-using-launchd/

Question or Comment?