Mac Scripting Overview

As of version 1.1.5, the Evernote for Mac client includes basic support for AppleScript.

The Evernote AppleScript Dictionary provides access to notebooks, tags, notes and a subset of their properties. In addition, the following operations are available:

create note
Provides the ability to create a new note from a file, a url, a snippet of text, or a snippet of HTML. Title, notebook, tags and creation date can optionally be specified as well.
create notebook
Allows for creation of a notebook, synchronized or local.
find notes
Provides the ability to query for a set of notes using Evernote's query syntax. (See Evernote's API Overview, Appendix C.)
export/import
Export and import notes to and from Evernote export XML files.
synchronize
Synchronize the Mac client with the Evernote servers.

For a full description of each command and its syntax, view the Evernote AppleScript dictionary in Apple's Script Editor application. The Script Editor can be found in /Applications/AppleScript/Script/Editor.app. To open the Evernote dictionary, choose "File > Open Dictionary..." and then select Evernote from the displayed list of applications.

Examples

-- EXAMPLE 1
-- Export all local-only notes, creating an archive file for each unsynchronized notebook

-- we're going to export to "/Users/xxxx/Documents/Evernote Local Notebooks Backup"
set documents_folder to (path to documents folder)
set backup_name to "Evernote Local Noteboooks Backup"

tell application "Finder"
-- make sure the destination folder exists
if not (exists folder backup_name of documents_folder) then
make new folder at documents_folder with properties {name:backup_name}
end if


-- get the full path
set backup_path to (folder backup_name of folder documents_folder as string)
end tell

tell application "Evernote"
-- we're just going to back up unsynchronized notebooks
set local_notebooks to every notebook whose notebook type is local only
repeat with localNB in local_notebooks
set localNotes to every note in localNB
-- export it to our backup folder as "<notebook name>.enex"
export localNotes to file (backup_path & name of localNB & ".enex")
end repeat
end tell


-- EXAMPLE 2
-- create a table that shows our disks and their percentage used
-- not exactly useful, but demonstrates creating a note from an HTML snippet

set _tableHeaderRow to "<tr><th>Disk Name</th><th>Percent Used</th></tr>"
set _tableDataRows to ""

tell application "Finder"
set _disks to every disk
repeat with _myDisk in _disks
-- get the percentange used for the disk
set _capacity to capacity of _myDisk
set _percentUsed to ((_capacity - (free space of _myDisk)) / _capacity * 100)
set _percentUsed to round _percentUsed


-- create a row for the HTML table
set _tableRow to "<tr><td>" & name of _myDisk & "</td><td>" & _percentUsed & "%</td></tr>"


-- add it to the rest of the rows
set _tableDataRows to _tableDataRows & _tableRow
end repeat
end tell

-- grab the machine name so we can put it in the note title
set _machineName to computer name of (system info)

-- create the full HTML table
set _tableHTML to "<table border=\"1\">" & _tableHeaderRow & _tableDataRows & "</table>"

-- and finally, create the note!
tell application "Evernote"