Hi, i finally got round to sorting out my alarm clock that ceased to work when switching to lepord (yes i know it was ages ago...i'm a busy man)
any way its a pretty basic applescript but thought i'd share...
any comments would be greatly appreciated - and if anyone knows how to speed up the ical event searching (it takes 9 seconds) let me know
my alarm clock says good morning, the current date and time, the current temperature and weather conditons (from internet), tells me how many unread emails i have, tells me if i have lectures today and then checks the tube status (London underground has a shockingly bad underground service)/tells me if i'm working/on holiday, and finally loads Capital Radio (Londoners will know this station)
it does a couple of other things like closing applications, messing around with the volume, snooze etc
here it is...
any way its a pretty basic applescript but thought i'd share...
any comments would be greatly appreciated - and if anyone knows how to speed up the ical event searching (it takes 9 seconds) let me know
my alarm clock says good morning, the current date and time, the current temperature and weather conditons (from internet), tells me how many unread emails i have, tells me if i have lectures today and then checks the tube status (London underground has a shockingly bad underground service)/tells me if i'm working/on holiday, and finally loads Capital Radio (Londoners will know this station)
it does a couple of other things like closing applications, messing around with the volume, snooze etc
here it is...
--mute Volume
set volume output volume 0
--Quit music/sound applications
tell application "QuickTime Player"
quit
end tell
tell application "iTunes"
quit
end tell
tell application "EyeTV"
quit
end tell
--get weather forcast
set TID to AppleScript's text item delimiters
set webadress to do shell script "curl http://i.wund.com/global/stations/03772.html#conditions"
-- Find temperature
set AppleScript's text item delimiters to ¬
"<span class=\"nowrap\"><b>"
set text1 to text item 3 of webadress
set AppleScript's text item delimiters to "</b>°"
set temp to text item 1 of text1
set temp to round (temp)
-- Find outlook
set AppleScript's text item delimiters to ¬
"<div>"
set text2 to text item 3 of webadress
set AppleScript's text item delimiters to "</div>"
set outlook to text item 1 of text2
set AppleScript's text item delimiters to TID
--Check new mail
tell application "Mail"
check for new mail
end tell
--find calendar items for today
tell (current date) to set today to its date string
set counter to 0
set counter1 to 0
tell application "iCal"
set e_vent to every event in calendar "University"
repeat with i from 1 to number of items in e_vent
set this_item to item i of e_vent
set startdate to start date of this_item
--set starttime to start of this_item
set startdate to date string of startdate
if startdate is today then
set counter to counter + 1
end if
end repeat
if counter is equal to 0 then
set e_vent1 to every event in calendar "WHSmith"
repeat with i from 1 to number of items in e_vent1
set this_item1 to item i of e_vent1
set startdate1 to start date of this_item1
set startdate1 to date string of startdate1
if startdate1 is today then
set counter1 to counter1 + 1
end if
end repeat
else
-- Find tube status
set TID to AppleScript's text item delimiters
set webadress to do shell script "curl http://www.tfl.gov.uk/tfl/livetravelnews/realtime/tube/tube-piccadilly-now.html"
set AppleScript's text item delimiters to ¬
"<p>"
set stat to text item 3 of webadress
set AppleScript's text item delimiters to "<br ><br ></p>"
set tubestat to text item 1 of stat
set AppleScript's text item delimiters to TID
end if
quit
end tell
--count unread emails
set unreadCount to 0
set exlcudeMailboxes to {"Drafts", "Trash", "Sent", "Sent Messages", "Junk", "Spam", "Outbox"}
tell application "Mail"
-- get mailboxes with unread count
set mailboxesWithUnreadMessages to mailboxes of accounts whose unread count is not 0
set localMailboxesWithUnreadMessages to every mailbox whose unread count is not 0
-- loop through all accounts and mailboxes
set returnArray to {}
repeat with currentAccount in mailboxesWithUnreadMessages & localMailboxesWithUnreadMessages
repeat with currentMailbox in currentAccount
-- get mailbox attributes
set mailboxName to name of currentMailbox
set mailboxCount to unread count of currentMailbox
if mailboxName is not in exlcudeMailboxes then
-- increment total count
set unreadCount to unreadCount + mailboxCount
end if
end repeat
end repeat
end tell
--open quicktime player
tell application "QuickTime Player"
run
end tell
-- get the time
on thetime()
-- hours
set timeStr to time string of (current date)
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
-- minutes
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
return (theHour & ":" & theMin & "") as string
end thetime
--Say good morning
set d to (date string of (current date))
set volume output volume 20
say "Good morning Aravinth, it is time to wake up."
delay 1
say "It is " & d
say "And the time is " & thetime()
set volume output volume 16
--say weather
delay 1
say "The current temperature in London is " & temp
say "degrees celcius"
say "and the outlook for today is " & outlook
--say number of unread emails and capital loading
delay 2
say "you have " & unreadCount
say "unread emails"
delay 2
--say calendar events
if counter is equal to 1 then
say "and one lecture today"
delay 2
say "the current tube status "
delay 0.5
say tubestat
else if counter is greater than 1 then
say "and " & counter
say "lectures today"
delay 2
say "the current tube status "
delay 0.5
say tubestat
else if counter1 is greater than 0 then
say "your calendar shows you have work today"
else
say "it appears you are on holiday as you have no lectures or work events in your calendar"
end if
--Open Captial FM stream in Quicktime Player
tell application "QuickTime Player"
open location "http://mediaweb.musicradio.com/V1/playlist.asx?StreamID=1"
end tell
say "Capital Radio is now loading"
--hide windows
tell application "System Events"
set visible of (every process whose visible is true and frontmost is false) to false
set visible of process "Finder" to false
end tell
--Fade in volume
delay 3
set volume output volume 5
delay 1
set volume output volume 6
delay 1
set volume output volume 7
delay 1
set volume output volume 8
delay 1
set volume output volume 9
delay 1
set volume output volume 10
delay 1
set volume output volume 11
delay 1
set volume output volume 12
delay 1
set volume output volume 13
delay 1
set volume output volume 14
delay 1
set volume output volume 15
delay 1
set volume output volume 16
delay 1
set volume output volume 17
delay 1
set volume output volume 18
delay 1
set volume output volume 19
delay 1
set volume output volume 20
delay 4
set volume output volume 19
delay 1
set volume output volume 18
delay 1
set volume output volume 17
delay 1
set volume output volume 16
--dialog boxes
set question to display dialog "Your Wake up routine has been completed sucessfully, what would you like to do?" buttons {"Continue listening to Capital Radio", "Snooze for 5 minutes", "Switch off Radio"} default button 1
set answer to button returned of question
if answer is equal to "Continue listening to Capital Radio" then
display dialog "Have a good day, the time is " & thetime() buttons {"OK!"} default button 1
end if
if answer is equal to "Snooze for 5 minutes" then
set volume output volume 0
display dialog "The volume has been muted for 5 minutes" buttons {"OK!"} default button 1
delay 298
set volume output volume 18
end if
if answer is equal to "Switch off Radio" then
tell application "QuickTime Player"
quit
end tell
display dialog "Capital Radio is now switched off" buttons {"close"} default button 1
end if