Thanks Nigel for all your help, I got it working brilliantly!
Here are some little tweaks I made and would like to share. I added some randomizing txt so it doesn’t get so repetitive.
::Greeting::
-- User Name
set userName to long user name of (system info)
-- Randomizer Greeting
property oldrandnum : missing value
set greetings to {"It's time to wake up!", "Rise and Shine!", "Snoozle doozle!", "Sleepy Head!", "Carpe Diem, seize the day!", "Tiger!"}
set countgreetings to length of greetings
repeat
set randnum to random number from 1 to countgreetings
if oldrandnum is missing value or (randnum ≠oldrandnum) or (countgreetings = 1) then
set oldrandnum to randnum
exit repeat
end if
end repeat
set greeting to item randnum of greetings
-- Time of Day
set the_hours to hours of (current date)
if the_hours is less than 8 then
say "Good Morning," & greeting
else if the_hours is less than 12 then
say "Good Morning" & userName
else if the_hours is less than 17 then
say "Good Afternoon" & userName
else
say "Good Evening" & userName
end if
-- Randomize Day
set currentday to (do shell script "date +%A")
-- Monday
if currentday is "Monday" then
set FirstDays to {"Happy Monday!", "It is Monday", "Today is Monday", "Sorry to be the bearer of bad news, but, it is Monday again"}
set FirstDay to some item of FirstDays
set currentday to SecondDay
-- Tuesday
else if currentday is "Tuesday" then
set SecondDays to {"Happy Tuesday!", "It's Taco Tuesday!", "Today is Tuesday"}
set SecondDay to some item of SecondDays
set currentday to SecondDay
-- Wednesday
else if currentday is "Wednesday" then
set ThirdDays to {"Happy Wednesday!", "Happy Hump day. The humpty dance is your chance, to do the hump...", "It is Wednesday", "Happy Hump day"}
set ThirdDay to some item of ThirdDays
set currentday to ThirdDay
-- Thursday
else if currentday is "Thursday" then
set ForthDays to {"It is Thirsty Thursday!", "Happy Thurday!", "Happy Friday-Eve", "Today is Thursday"}
set ForthDay to some item of ForthDays
set currentday to ForthDay
-- Friday
else if currentday is "Friday" then
set FifthDays to {"Happy Friday!", " You are all most there, tomorrow's the weekend", "One day to go, tomorrow is Saturday", "It is Friday", "It is Friday"}
set FifthDay to some item of FifthDays
set currentday to FifthDay
-- Saturday
else if currentday is "Saturday" then
set SixthDays to {"Happy Saturday", "Huzzuh today is Saturday", "It is Saturday", "I hope you have Great Saturday"}
set SixthDay to some item of SixthDays
set currentday to SixthDay
-- Sunday
else if currentday is "Sunday" then
set SeventhDays to {"Happy Sunday", "Welcome to Sunday Funday", "Today is Sunday bloody Sunday", "I hope you are enjoying your Sunday", "It is Sunday"}
set SeventhDay to some item of SeventhDays
set currentday to SeventhDay
end if
delay 0.3
say currentday
delay 0.3
say "the time right now is " & getTimeInHoursAndMinutes()
on getTimeInHoursAndMinutes()
-- Get the "hour"
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
-- 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 "AM or PM"
set Pos to offset of " " in timeStr
set theSfx to characters (Pos + 1) through end of timeStr as string
return (theHour & ":" & theMin & " " & theSfx) as string
end getTimeInHoursAndMinutes
-OR-
::More simple greeting version::
-- Randomizer Greeting
property oldrandnum : missing value
set greetings to {"It's time to wake up!", "Rise and Shine!", "Snoozle doozle!", "Sleepy Head!", "Carpe Diem, seize the day!", "Tiger!"}
set countgreetings to length of greetings
repeat
set randnum to random number from 1 to countgreetings
if oldrandnum is missing value or (randnum ≠oldrandnum) or (countgreetings = 1) then
set oldrandnum to randnum
exit repeat
end if
end repeat
set greeting to item randnum of greetings
#set userName to long user name of (system info)
-- Time of Day Greeting
set the_hours to hours of (current date)
if the_hours is less than 8 then
say "Good Morning," & greeting
else if the_hours is less than 13 then
say "Good Morning"
else if the_hours is less than 18 then
say "Good Afternoon"
else
say "Good Evening"
end if
delay 0.5
say "it is " & getTimeInHoursAndMinutes()
on getTimeInHoursAndMinutes()
-- Get the "hour"
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
-- 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 "AM or PM"
set Pos to offset of " " in timeStr
set theSfx to characters (Pos + 1) through end of timeStr as string
return (theHour & ":" & theMin & " " & theSfx) as string
end getTimeInHoursAndMinutes
::Local Weather:: You’ll need to replace the CityCode with your local one & towards the bottom of the script the name of the City.
--this is the city code. Search the code for your city on http://weather.yahoo.com/
set CityCode to 2430683
--temperature format
set t_format to "F"
--voiceover format
set v_format to "S"
--say present condition
set a_format to "Y"
set IURL to "http://weather.yahooapis.com/forecastrss?w=" & CityCode
--downloading the file using curl
set file_content to (do shell script "curl " & IURL)
--looking for the line with actual condition
set theText to text ((offset of "yweather:condition" in file_content) + 1) thru -1 of file_content
set sub_1 to text ((offset of "\"" in theText) + 1) thru -1 of theText
--today conditions found
set actual_condition to text 1 thru ((offset of "\"" in sub_1) - 1) of sub_1
--looking for actual temperature temperature
set sub_1a to text ((offset of "temp=" in sub_1)) thru -1 of sub_1
set sub_1b to text ((offset of "\"" in sub_1a) + 1) thru -1 of sub_1a
set actual_temp to text 1 thru ((offset of "\"" in sub_1b) - 1) of sub_1b
if t_format is equal to "C" then
set actual_temp to (5 / 9) * (actual_temp - 32) as integer
end if
--looking for today forecast
set theText to text ((offset of "yweather:forecast" in file_content) + 1) thru -1 of file_content
set sub_2 to text ((offset of "\"" in theText) + 1) thru -1 of theText
--maximum and minimum temperatures found
set today_min_temp to word 9 of sub_2
set today_max_temp to word 12 of sub_2
if t_format is equal to "C" then
set today_min_temp to (5 / 9) * (today_min_temp - 32) as integer
set today_max_temp to (5 / 9) * (today_max_temp - 32) as integer
end if
--looking for today forecast condition (a bit tricky)
set sub_3 to text ((offset of "text" in sub_2) + 1) thru -1 of sub_2
set sub_4 to text ((offset of "\"" in sub_3) + 1) thru -1 of sub_3
set today_forecast to text 1 thru ((offset of "\"" in sub_4) - 1) of sub_4
--looking for tomorrow forecast
set sub_5 to text ((offset of "yweather:forecast" in sub_4) + 1) thru -1 of sub_4
set sub_6 to text ((offset of "\"" in sub_5) + 1) thru -1 of sub_5
--maximum and minimum temperatures found
set tomorrow_min_temp to word 9 of sub_6
set tomorrow_max_temp to word 12 of sub_6
if t_format is equal to "C" then
set tomorrow_min_temp to (5 / 9) * (tomorrow_min_temp - 32) as integer
set tomorrow_max_temp to (5 / 9) * (tomorrow_max_temp - 32) as integer
end if
set sub_7 to text ((offset of "text" in sub_6) + 1) thru -1 of sub_6
set sub_8 to text ((offset of "\"" in sub_7) + 1) thru -1 of sub_7
set tomorrow_forecast to text 1 thru ((offset of "\"" in sub_8) - 1) of sub_8
if v_format is equal to "L" then
say "The current conditions in Kansas City are: " & today_forecast & ". Outside temperature will be: between " & today_min_temp & " and " & today_max_temp & " degrees.
Tomorrow: " & tomorrow_forecast & ", with a low of " & tomorrow_min_temp & ", and a high of " & tomorrow_max_temp & " degrees"
else
say "The current weather in Kansas City is: " & today_forecast & ", between " & today_min_temp & ", and " & today_max_temp & " degrees.
Tomorrow: " & tomorrow_forecast & ", with a low of " & tomorrow_min_temp & " ,and a high of " & tomorrow_max_temp & " degrees"
end if
:
: Added some random txt to break up the “You have a Meeting” so it sound more natural.
set calendarNames to {"Home", "Work"}
set today to (current date)
set today's time to 0
set tomorrow to today + days
set myMeetings to {}
repeat with calName in calendarNames
-- Get the start dates of all the events in this calendar.
-- It could take some time if there are a lot of events.
tell application "Calendar" to set thisCalendarsStartDates to start date of every event of calendar calName
-- Examine the start dates and act on those which occur today.
repeat with evnt from 1 to (count thisCalendarsStartDates)
set theStartDate to item evnt of thisCalendarsStartDates
if ((theStartDate is greater than or equal to today) and (theStartDate is less than tomorrow)) then
-- If this start date occurs today, get further information from the event to which it belongs.
tell application "Calendar" to set {summary:theSummary, end date:theEndDate, allday event:allDayEvent} to event evnt of calendar calName
-- If the event's a 24-hour all-day event, or an ordinary event which ends today, prepare appropriate spoken text.
set theTime to missing value
if (allDayEvent) then
if (theEndDate is theStartDate + days) then set theTime to "First, there is an All-day event"
else if (theEndDate is less than or equal to tomorrow) then
-- Get a representation of the start time in 12-hour time.
set {hours:Eventhour, minutes:Eventminute} to theStartDate
set pre to item (Eventhour div 12 + 1) of {"AM", "PM"}
set Eventhour to (Eventhour + 11) mod 12 + 1
if (Eventminute is 0) then set Eventminute to ""
set theTime to "at " & Eventhour & " " & Eventminute & " " & pre
end if
-- Put both the start date and the meeting text into the meetings list as a pair.
set conjunctions to {" you have scheduled,", " there is,", " you have a meeting,"}
set conjunction to some item of conjunctions
if (theTime is not missing value) then set the end of myMeetings to {theStartDate, theTime & conjunction & theSummary}
end if
end repeat
end repeat
-- Custom comparer for a customisable sort. It compares lists by their first items.
script sortOnItem1
on isGreater(a, b)
return (item 1 of a > item 1 of b)
end isGreater
end script
-- Sort items 1 thru -1 of myMeetings using sortOnItem1 to compare them ” ie. sort on the start dates.
CustomInsertionSort(myMeetings, 1, -1, {comparer:sortOnItem1})
-- Speak the prepared texts (item 2 of each item of myMeetings) in order.
set greetings to {"Let's take a quick look at your calendar.", "Let's see what you have going on today.", "Let's see how busy your day looks.", "Here's whats on your calendar."}
set greeting to some item of greetings
say greeting
delay 0.5
set numberOfMeetings to (count myMeetings)
if (numberOfMeetings is 0) then
set preamble to "You have nothing on your schedule for today,"
else if (numberOfMeetings is 1) then
set preamble to "There is one event for today"
else
set preamble to "You better get moving, there are " & numberOfMeetings & " upcoming appointments."
end if
say preamble
delay 1
repeat with thismeeting in myMeetings
say item 2 of thismeeting
delay 0.5
end repeat
say "That's everything for," & (date string of today)
on CustomInsertionSort(theList, l, r, customiser)
script o
property comparer : me
property slave : me
property lst : theList
on isrt(l, r)
set u to item l of o's lst
repeat with j from (l + 1) to r
set v to item j of o's lst
if (comparer's isGreater(u, v)) then
set here to l
set item j of o's lst to u
repeat with i from (j - 2) to l by -1
tell item i of o's lst
if (comparer's isGreater(it, v)) then
set item (i + 1) of o's lst to it
else
set here to i + 1
exit repeat
end if
end tell
end repeat
set item here of o's lst to v
slave's shift(here, j)
else
set u to v
end if
end repeat
end isrt
-- Default comparison and slave handlers for an ordinary sort.
on isGreater(a, b)
(a > b)
end isGreater
on shift(a, b)
end shift
end script
-- Process the input parameters.
set listLen to (count theList)
if (listLen > 1) then
-- Negative and/or transposed range indices.
if (l < 0) then set l to listLen + l + 1
if (r < 0) then set r to listLen + r + 1
if (l > r) then set {l, r} to {r, l}
-- Supplied or default customisation scripts.
if (customiser's class is record) then set {comparer:o's comparer, slave:o's slave} to (customiser & {comparer:o, slave:o})
-- Do the sort.
o's isrt(l, r)
end if
return -- nothing.
end CustomInsertionSort
ENJOY! Let me know if someone finds a way to speed up the calendar. The delay at the beginning isn’t horrible but I would love to see it get faster. Also if anyone know of a way to figure out a script to determine the time until your next event of the current day, that would be helpful. For instance “Good after noon, UserName, the time is 11:35 AM… You have 25 minutes until your next work event titled [Lunch Meeting]!” Thanks!