April 19th, 2011Creating custom actions in Quicksilver
I recently wanted to setup a custom action in Quicksilver to do a simple task. Take any text I provide in the Object pane and write it to a file with a bit more around it.
After trying to write something in applescript and quickly giving up, I found an article that would allow me to write a custom action in Ruby.
Create a custom ruby script and put it into ~/Library/Application Support/Quicksilver/Actions (you may have to create the Actions directory)
This is what my script looks like. It’s ‘addTodo.rb’ I used this as an opportunity to try and pick up some ruby too so please forgive any newbie faux pas. This script creates a CSV and appends to it so I can open it in Excel or something similar.
#!/usr/bin/ruby
# writes to a file with a date
todo = ARGV[0]
now = Time.now
filename = "/Users/anoop/Documents/todos/todo.csv"
if !File.exists?(filename) thenend
filehandle = File.open(filename, "w")
filehandle.puts "Week Number, Time of Update, Update"
else
filehandle = File.open(filename, "a")
# format the date so that we have the week #, the current date and then the buffer
todobuff = now.strftime(“\”Week %U\”, \”%a %m/%d/%Y %H:%M:%S\”,”) + “\”" + todo + “\”"
filehandle.puts todobuff
filehandle.close
Save this file and restart Quicksilver (I had to restart it twice)
Activate Quicksilver, and type in
.your item for the todo list
In the action window, simply type search for ‘addTodo’ and you should see your newly added action. Execute and then confirm that the script was executed successfully.
Enjoy!
