Last active
December 15, 2015 22:10
-
-
Save maripo/5330603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------------------- | |
-- createnote.applescript | |
-- Evernote Command Line Proxy | |
-- by Maripo Goda <goda.mariko[at]gmail.com> | |
-- Required: | |
-- Mac OS X + AppleScript | |
-- Evernote for Mac OS X | |
-- Usage: | |
-- Create a note with text | |
-- > osascript createnote.applescript --title='Sample Note 1' --text='Test Text' | |
-- 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' | |
-------------------------------------------------- | |
on getParamValue(param, paramName, defaultValue) | |
set val to do shell script "echo '" & param & "' | sed -E 's/(--" & paramName & "=(.*)|.*())/\\2/g'" | |
if length of val is 0 then | |
return defaultValue | |
else | |
val | |
end if | |
end getParamValue | |
on run argv | |
set myTitle to "" | |
set myText to "" | |
set myHtml to "" | |
set myUrl to "" | |
set myFile to "" | |
repeat with param in argv | |
set myTitle to getParamValue(param, "title", myTitle) | |
set myText to getParamValue(param, "text", myText) | |
set myHtml to getParamValue(param, "html", myHtml) | |
set myUrl to getParamValue(param, "url", myUrl) | |
set myFile to getParamValue(param, "file", myFile) | |
end repeat | |
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