Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Clip to Evernote via Quicksilver and AppleScript Apps
The latest release of Evernote includes very straightforward AppleScript support. Hopefully someone will build an Evernote plug-in for Quicksilver, but in the meantime here is a script for clipping text directly from Quicksilver into Evernote:
(*

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
Create the script in ScriptEditor, and install it by placing it in ~/Library » Application Support » Quicksilver » Actions, then restarting Quicksilver. (Configuration instructions are in the top of the script.)

To use this script, 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. Here are a few 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.
[robg adds: I haven't tested this one.]
    •    
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[16,948 views]  

Clip to Evernote via Quicksilver and AppleScript | 9 comments | Create New Account
Click here to return to the 'Clip to Evernote via Quicksilver and AppleScript' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Clip to Evernote via Quicksilver and AppleScript
Authored by: jedverity on Fri, Oct 3 2008 at 7:27PM PDT
Note: as of 10/3/08 at 10:00 EDT the script above is posted incorrectly. A proper version can be found here: Clip to Evernote

[ Reply to This | # ]
Clip to Evernote via Quicksilver and AppleScript
Authored by: robg on Sat, Oct 11 2008 at 6:34AM PDT
The script should now be correct. Sorry for the errors.

-rob.

[ Reply to This | # ]
Clip to Evernote via Quicksilver and AppleScript
Authored by: Rubin421 on Mon, Oct 20 2008 at 9:39AM PDT
On my machine with the latest version of everything, both scripts have the same issue: if I don't specify a notebook to put the note into, nothing happens (i.e., the script doesn't create a note in the default notebook).

[ Reply to This | # ]
Clip to Evernote via Quicksilver and AppleScript
Authored by: jedverity on Sat, Nov 1 2008 at 10:05AM PDT
Sorry! Here is a replacement with that fixed.


--begin code

property defaults : {notebook:"", tags:"", title:""}
property special_delim : ";"

global txt, pspecial, cpos

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)
if nb ≠ "" then
tell application "Evernote" to create note with text n title t notebook nb tags tg
else
tell application "Evernote" to create note with text n title t tags tg
end if
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

--end code


[ Reply to This | # ]
Clip to Evernote via Quicksilver and AppleScript
Authored by: decavolt on Wed, Dec 17 2008 at 2:56PM PST
Rubin421 - If you set a default notebook in the Applescript, your clips will post to Evernote properly. Otherwise, you need to specify a notebook in the clip.

property defaults : {notebook:"NOTEBOOK NAME HERE", tags:"", title:"untitled"}


[ Reply to This | # ]
Clip to Evernote via Quicksilver and AppleScript
Authored by: pattulus on Sun, Jan 25 2009 at 4:47PM PST
I'm yearning for a Launchbar version of this one. I tried to rewrite it, so that I could trigger the applescript via Launchbar, but had no success :[

anyone with brains around here who can rewrite this?

[ Reply to This | # ]
Clip to Evernote via Quicksilver and AppleScript
Authored by: jwedwards74 on Thu, Jun 11 2009 at 7:10AM PDT
Excellent Tip, thanks so much!

[ Reply to This | # ]
Clip to Evernote via Quicksilver and AppleScript
Authored by: Landdogger on Mon, Jan 18 2010 at 9:09AM PST
This is really great, thanks for the all the work!

Is there a quick fix so that the text entered does not have to be case sensitive?

[ Reply to This | # ]
Clip to Evernote via Quicksilver and AppleScript
Authored by: retractable on Wed, Feb 3 2010 at 6:54AM PST
Great! Thanks for posting this retractable lanyard

[ Reply to This | # ]