(*
Clip to Evernote for Quicksilver, by Jed Verity junk@veritys.com
INSTALLATION
1. Put this script in ~/Library/Application Support/Quicksilver/Actions/
2. Restart Quicksilver
CONFIGURATION
Set default values in the "defaults" property below.
- Tags must be separated by spaces (so multiple word tags would not work)
- Notebooks and tags are case-sensitive. If it doesn't match properly it won't work at all.
USAGE
When you have text in your first Quicksilver pane, select "Clip to Evernote" (or whatever you call this script if you change the name).
The text format is as follows: You must have a title or note (or both), but everything else is optional.
title:your note here nb:notebook tags:space-separated tags here
The only thing that matters is that any specified notebook or tags must come after title and note.
EXAMPLES
1. this is a note with no title or anything
- creates note with your default title, notebook, tags, if specified, otherwise just goes straight into Evernote as is
2. todo:buy batteries
- creates note with title "todo" and note "buy batteries"
3. remember to buy batteries: tags:todo household
- creates note with title "remember to buy batteries" and tags "todo" and "household"
4. great idea for meeting: tell everyone to put 20% of salary in mattress nb:Work tags:meeting finance meltdown
- creates note "tell everyone to put 20% of salary in mattress" with title "great idea for meeting" in notebook "Work" with tags "meeting", "finance", and "meltdown"
*)
property defaults : {notebook:"", tags:"", title:""}
property special_delim : ";"
global txt, pspecial, cpos
--my mainprogram("")
using terms from application "Quicksilver"
on process text qtxt
my mainprogram(qtxt)
end process text
end using terms from
on initvars(qtxt)
copy qtxt to txt
set pspecial to 10000000
end initvars
on mainprogram(qtxt)
my initvars(qtxt)
set ztags to getdata("tags:", defaults's tags)
set znotebook to getdata("nb:", defaults's notebook)
set ztitle to gettitle()
if pspecial < txt's length then
set pend to (pspecial - 2)
else
set pend to txt's length
end if
set znote to getnote(pend)
set ztags to itemize(ztags, " ")
--return {ztitle, znote, znotebook, ztags}
my CreateEvernote(ztitle, znote, znotebook, ztags)
end mainprogram
to CreateEvernote(t, n, nb, tg)
tell application "Evernote" to create note with text n title t notebook nb tags tg
end CreateEvernote
to getdata(label, default)
set o to offset of label in txt
if o > 0 then
if o < pspecial then
set pspecial to o
end if
set chunk to my trim(itemize(txt, label)'s item 2 as string)
if label = "nb:" then
set nxt to "tags:"
else
set nxt to "nb:"
end if
set chunk to my trim(itemize(chunk, nxt)'s item 1 as string)
if (offset of special_delim in chunk) is not false then
return itemize(chunk, special_delim)'s item 1
else
return chunk
end if
else
return default
end if
end getdata
to getnote(meta_start_pos)
try
set start_pos to cpos + 1
on error
set start_pos to 1
end try
if start_pos > meta_start_pos then
return ""
else
return my trim(text start_pos thru meta_start_pos of txt)
end if
end getnote
to gettitle()
set title to my getdata("title:", defaults's title)
if title = "" then
set cpos to offset of ":" in txt
if cpos > 0 then
set title to my trim(text 1 thru (cpos - 1) of txt)
end if
end if
return title
end gettitle
to itemize(var, delim)
set delims_old to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
if var's class = list then
set txt_new to var as text
else
set txt_new to var's text items
end if
set AppleScript's text item delimiters to delims_old
return txt_new
end itemize
on trim(someText)
repeat until someText does not start with " "
set someText to text 2 thru -1 of someText
end repeat
repeat until someText does not end with " "
set someText to text 1 thru -2 of someText
end repeat
return someText
end trim