The Blog of Brad
CODE: GrowlHotClock.scpt
Leo Laporte has an AppleScript he uses to time himself out for his weekend radio show as the show is syndicated and if he continues past a certain time will be cut off by commercials, and so wrote an AppleScript, hotclock.scpt, it uses Quicksilver for notifications. I thought this would be of use for any viewers/listeners of his show, and so I re-wrote the tellhost() calls in it to use Growl (to be less annoying). Here is my updated code. However you may want to change the times listed to offset the radio/internet delay…
--the commercials are at the same time every hour, so the times listed are only the minutes:seconds
property wraps : {"17:05", "28:05", "45:05", "56:55"}--these times are 1 minutes less than 'break'
property breaks : {"18:05", "29:05", "46:05", "57:55"}--change these to offset the radio delay
property countdown : {"10", "9", "8", "7", "6", "5", "4", "3", "2", "1", "Break!"}-- do not change
global currentSegment, breakTime, wrapTime
on run
-- find current segment
set now to getTime()
set currentSegment to 1
set wrapTime to item currentSegment of wraps
repeat until now is less than wrapTime
-- keep going until the next segment
if currentSegment is greater than or equal to (length of wraps) then
set currentSegment to 1
else
set currentSegment to currentSegment + 1
end if
set wrapTime to item currentSegment of wraps
end repeat
end run
on idle
-- runs until applet is quit
set now to getTime()
set wrapTime to item currentSegment of wraps
if now is greater than or equal to wrapTime then
-- there's a minute (or less) left
tellHost("Wrap...")
set breakTime to item currentSegment of breaks
repeat until now is greater than or equal to breakTime
set now to getTime()
end repeat
-- in final ten seconds, display countdown
repeat with msg in countdown
tellHost(msg)
-- delay 1
end repeat
-- go to next break time
if currentSegment is greater than or equal to (length of breaks) then
set currentSegment to 1
else
set currentSegment to currentSegment + 1
end if
set waitTime to (10 * minutes) -- don't come back for 10 minutes
else
set waitTime to 5 -- check every five seconds so as not to use cycles unnecessarily
end if
return waitTime
end idle
-- subroutines
on tellHost(message)
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to {"Wrap", "Break", "Other", "Countdown"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to {"Wrap", "Break", "Countdown"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"Growl Hotclock" all notifications allNotificationsList default notifications enabledNotificationsList
if message is "Wrap" then
set nName to "Wrap"
else if message is "Break!" then
set nName to "Break"
else
set nName to "Countdown"
end if
-- Send a Notification...
notify with name nName title message description "from Hot Clock" application name "Growl Hotclock"
end tell
end tellHost
on getTime()
set timeStr to time string of (current date)
-- Get the "hour"
set Pos to offset of ":" in timeStr
set theHour to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
-- Get the "minute"
set Pos to offset of ":" in timeStr
set theMin to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
--Get the "second"
set Pos to offset of " " in timeStr
set theSec to characters 1 thru (Pos - 1) of timeStr as string
return (theMin & ":" & theSec) as string
end getTime
| Print article | This entry was posted by BradArsenault on February 2, 2009 at 6:10 pm, and is filed under Blog. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

















Comments are closed.