Quick world time lookup using Alfred and Growl
I’ve been an avid Alfred user since its early days. It’s just one of these pieces of software that you get attached to and want to use for everything. Alfred is a fast, lightweight and friendly app launcher. But it’s also much more than that. Terminal shortcuts, custom searches and clipboard snippets are probably my top used features in addition to the app launching and file browser. I’d recommend checking it out if you haven’t already. The powerpack is worth every single penny.
Anna’s article about setting up a custom search to quickly navigate to a Worldtime Buddy reminded me of something I do quite often when I want to quickly tell the current time is it in any city around the world. Especially handy if you work with a team whose members are scattered all over the world. I often just ask Google. For example, searching for “time in sydney” gives you the current time in Sydney, along with the search results. Which, at that point, is basically just jargon.
In Alfred you can simply use ‘google time in sydney’ which would open a new tab in your browser and basically do the above. But I wanted something even quicker and does not involve opening a new browser tab that I’d be closing 3 seconds after.
Enter timeinplace, a small and simple script that hits that search page, grabs that line of text and displays it in a Growl notification.
Here’s how.
Download the script and place it somewhere convenient. I often put my own scripts in ~/bin/ which I’ve already added to my $PATH.
You will need to make that script executable
chmod +x timeinplace
And you will also need to install the nokogiri and rb-appscript gems if you don’t have them already.
gem install nokogiri rb-appscript
Now open Alfred Preferences, and navigate to the ‘Terminal/Shell’ section. Use the ‘+’ button under the shortcuts list to add a new shortcut.

Use whatever you like for ‘Title’, ‘Description’ and ‘Keyword’. The latter is what you will be using to run the script, so I recommend something short and easy. I use ‘time’ so I can type in ‘time in city’ like I’m used to.
For ‘Command’ put in timeinplace"{query}", make sure ‘Quotes’ is checked and save the shortcut. Don’t forget to check the ‘Silent’ checkbox next to your shortcut in the list. This will tell Alfred not to execute the script in a visible terminal window.
Tip: If you are having trouble getting the script to work in Silent mode, try using the absolute path to the script in ‘Command’ instead. i.e. ~/bin/timeinplace "{query}" in my case.
That’s it. Fire Alfred and type in ‘time in melbourne’, a second or two to wait, and…

For those who only wanted to take a look, here’s the script
#!/usr/local/bin/ruby
require 'open-uri'
require 'cgi'
require 'nokogiri'
require 'appscript'
include Appscript
query = ARGV[0]
exit if query.nil?
begin
url = "http://www.google.com/search?q=time+#{CGI.escape(query)}"
res = Nokogiri::HTML(open(url)).at("li.tpo").text
description, title = res.split(' - ')
rescue
title = "Cannot find time"
description = "Cannot find timne for '#{query}'"
end
growl = app("GrowlHelperApp")
notifications = ["TimeInPlace"]
growl.register(
:as_application => "TimeInPlace",
:all_notifications => notifications,
:default_notifications => notifications
)
growl.notify(
:with_name => "TimeInPlace",
:title => title,
:description => description,
:application_name => "TimeInPlace",
:icon_of_application => "Alfred"
)
Enjoy.
Update: Slightly refactored the script to use the appscript library instead of the ugly applescript wrapped in an uglier system().
You can respond to this article by replying on twitter or sending me an email.