Alfred & Evernote

Two apps I use continuously on a daily basis are Alfred, the best app launched for OS X, and Evernote, a slick note taking app that syncs across multiple platforms (Mac, Web, iOS and even... Windows). I jumped on the Alfred band wagon pretty early on. When Andrew Pepperrell started rolling it out I was impressed by the speed and general performance of the app. Once the PowerPack rolled out I was sold, ditching my Google Launcher, Quicksilver and the Launchbar trial I was unsatisfied with. Alfred improves my productivity, it really pumps up my workflow and makes doing things faster. If you haven't tried a launcher, you're missing out. If you have tried a launcher, but haven't tried Alfred then you're really missing out! Alfred is free and if you want you can sup it up with the PowerPack, which I strongly recommend.
![]()
Evernote has become a pretty big part of my workflow since I took my new job. I'm constantly making notes about code, servers and personnel in it for later reference. I love that I can switch from my work station in the office to a meeting and have access to all my notes on my iPad; or get in the car and drive home and be able to reference something when I get a phone call from my boss by pulling up Evernote on the iPhone. So Thursday night, I wondered how could I mary these two awesome apps together...
Welcome to AppleScript. AppleScript is a scripting language supported all over OS X that lets you do stuff with your favorite applications. Any app worth a diddily-doo either has AppleScript support or is working on it. Evernote happens to have some pretty awesome AppleScript support that lets you programmatically create notes. Meanwhile, Alfred has some great terminal integration that allows calling scripts in an abbreviated form and passing it user-inputted text. Meet osascript, a way of executing AppleScripts from the terminal. Thursday night I started fiddling around with this and wrote an AppleScript that I could call from Alfred and use to add notes directly to Evernote.
So how did I do this? First step is to write an AppleScript to make it happen. This is what mine looks like:
on run argv
set theTitle to (item 1 of argv) as string
set theNote to (item 2 of argv) as string
tell application "Evernote"
create note title theTitle with text theNote
end tell
end runBasically this little script takes arguments passed in from the command line, sets them to variables I can use and then tells the Evernote app to create a new note with them. It's pretty dead-simple. A couple of things to note... I don't activate Evernote here, so if it's open and in the background it stays there. This was done on purpose, because a lot of times I want to quickly add a note without disrupting my workflow. Your mileage may vary and you may want to do things a little differently.
Growl support is not included in the above chunk of code. For those that aren't familiar with Growl you should check it out. It is a notification system for OS X, and I wanted to use it so that when I add a note to Evernote I still know about it - even if I am not activating the Evernote application. So, using some more AppleScript and examples from Growl's website I added the following chunk of code:
on growlNotify(message)
tell application "System Events"
set isRunning to ¬
(count of (every process whose name is "GrowlHelperApp")) > 0
end tell
if isRunning then
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Evernote"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to ¬
{"Evernote"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"Evernote Note Script" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Evernote"
-- Send a Notification...
notify with name ¬
"Evernote" title ¬
"Evernote" description ¬
message application name "Evernote Note Script"
end tell
end if
end growlNotifyAnd then in my original ditty for Evernote I added the following after the note is created:
set message to "Added " & quote & theTitle & quote my growlNotify(message)
Lastly, I set up Alfred to run this when I type "evernote" in it:
Basically here I pass that osascript binary my scriptlet and then the add the text for my note after it. The command essentially takes two parameters, a title and a note. Those chunks of text need to be wrapped in quotes so that spaces don't throw off osascript and make more arguments then we want. Adding the arguments in quotes also allows us to distinguish the title from the note. This is what the full command to Alfred looks like when I type it in the launcher:
evernote "Note title" "Note body"
And that's how I make notes in Evernote from Alfred. You can download a copy of my entire script by clicking here (it's hosted on DropBox).
In a day or so I'll post about how I did the same thing with OmniFocus.
UPDATE: In the final script, which you can download via DropBox, I added a suggestion from Posterous user spobo which automatically tags notes created from Alfred as "alfred". Mega props to spobo for this addition!
