Skip to content

Instantly share code, notes, and snippets.

@maripo
Created March 5, 2013 02:22
Show Gist options
  • Save maripo/5087497 to your computer and use it in GitHub Desktop.
Save maripo/5087497 to your computer and use it in GitHub Desktop.
Evernote Local API Command Line Proxy
--------------------------------------------------
-- createnote.applescript
-- Evernote Command Line Proxy
-- by Maripo Goda <goda.mariko[at]gmail.com>
-- Required:
-- Mac OS X + AppleScript
-- Evernote for Mac OS X
-- Perl + JSON.pm
-- Usage:
-- Create a note with text
-- > osascript createnote.applescript '{"title":"Sample Note 1" , "text":"Hello Evernote Local API!"}'
-- Create a note with HTML
-- > osascript createnote.applescript '{"title":"Sample Note 2" , "html":"<strong>HELLO!!!</strong>"}'
-- Create a note from URL
-- > osascript createnote.applescript '{"title":"Sample Note 3" , "url":"http://blog.maripo.org"}'
-- Create a note from a local file
-- > osascript createnote.applescript '{"title":"Sample Note 4" , "file":"/foo/bar/baz.txt"}'
--------------------------------------------------
to getJsonPrpoerty(json, propertyName)
set shell to "echo '" & json & "' | perl -e \"use JSON;print from_json(<STDIN>)->{" & propertyName & "}\""
set val to do shell script shell
return val
end getJsonPrpoerty
on run argv
set myTitle to getJsonPrpoerty(item 1 of argv, "title")
set myText to getJsonPrpoerty(item 1 of argv, "text")
set myHtml to getJsonPrpoerty(item 1 of argv, "html")
set myUrl to getJsonPrpoerty(item 1 of argv, "url")
set myFile to getJsonPrpoerty(item 1 of argv, "file")
log "title:" & myTitle
log "text:" & myText
log "html:" & myHtml
log "url:" & myUrl
log "file:" & myFile
tell application "Evernote"
set myNote to null
if myText is not equal to "" then
set myNote to create note title myTitle with text myText
else if myHtml is not equal to "" then
set myNote to create note title myTitle with html myHtml
else if myUrl is not equal to "" then
set myNote to create note title myTitle from url myUrl
else if myFile is not equal to "" then
set myNote to create note title myTitle from file myFile
end if
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment