The following script is an elegant way to grab the time for any city in the world and display it using the growl notification system.
#!/bin/bash ########################################################################### ## Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3 ## ## Please see: http://www.gnu.org/licenses/gpl.html for legal details, ## ## rights of fair usage, the disclaimer and warranty conditions. ## ########################################################################### # Check that we have at least one argument. if [ $# -eq 0 ]; then echo "Usage: `basename $0` <CITY>" exit 1 fi # Read in the city from command line. for arg in "$@"; do QUERY_CITY=$QUERY_CITY"+"$arg CITY=$CITY" "$arg done # Fetch from Google. RESULT=`curl --user-agent "" "http://www.google.co.uk/search?q=time+now+in$QUERY_CITY" -s | egrep -o "<b>[0-9]+:[0-9]{2,}<\/b>"` # Clean the bold anchors. RESULT=`echo $RESULT | sed 's/<b>//g' | sed 's/<\/b>//g'` # Make growl display the result. osascript<<END tell application "System Events" set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0 end tell if isRunning then tell application "GrowlHelperApp" -- The following line was used when creating a standalone script. -- set the googletime to do shell script "curl --user-agent \"\" \"http://www.google.co.uk/search?q=time+now+in+new+jersey\" -s | egrep -o \"[0-9]+:[0-9]{2,}\"" set the allNotificationsList to {"GoogleTime"} set the enabledNotificationsList to {"GoogleTime"} register as application "GoogleTime" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "GrowlHelperApp" -- Send the notification... notify with name "GoogleTime" title $(echo "\""$CITY"\"") description $(echo "\""$RESULT"\"") application name "GoogleTime" end tell end if END
bash
script could be triggered directly as an individual application by creating one in the AppleScript editor. The bash
part is responsible for processing input and then runs the AppleScript part using the osascript
command line utility.curl
will not successfully retrieve a google search page if it does not use the –user-agent ""
option. It will get a permission denied page instead.google.co.uk
. This is done in order to prevent getting a redirect page instead of the query result page.-o
option to egrep
is responsible for displaying only the matched text instead of the entire line and egrep
is used instead of grep
in order to have the advanced (add-on) regex features.For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.