Applescript & iCal announce multiple events

I’m trying to get a script working that will pull events within a Calendar and announce them using macintalk. However when I run the script it announces both events in the same line. Example "You have two meetings today, they are titled, “Test, Test2 and is at 9pm”

It calls out the names of both events and only the time of one of the events.

What I would like it to do is this, “You have two meetings today. At 7pm you have a meeting titled Test. And at 9pm you have a meeting titled Test2”

Here is the code that I am currently using.


set tomorrow to (current date) + 1 * days
set myMeetings to {}
tell application "iCal"
	tell calendar "Meetings"
		set futureEvents to every event whose start date is greater than or equal to (current date) and end date is less than or equal to tomorrow
		repeat with anEvent in futureEvents
			set EventProperties to properties of anEvent
			if not (allday event of EventProperties) then
				set pre to "AM"
				set Eventhour to hours of start date of EventProperties
				set Eventminute to minutes of start date of EventProperties
				if (Eventhour > 12) then
					set Eventhour to (Eventhour - 12)
					set pre to "PM"
				end if
				
			end if
			copy the summary of anEvent & ". " to the end of myMeetings
		end repeat
	end tell
end tell
if (count myMeetings) is less than 1 then
	say "you do not have any meetings today." using "Alex"
end if
if (count myMeetings) is equal to 1 then
	say "you have" & (count myMeetings)
	say "meeting today"
	delay 1
	if Eventminute is equal to 0 then
		say "Your meeting is titled " & myMeetings
		say "and is at "
		say Eventhour
		say pre
	else
		say "Your meeting is title " & myMeetings
		say "and is at "
		say Eventhour
		say Eventminute
		say pre
	end if
end if
if (count myMeetings) is greater than 1 then
	say "you have" & (count myMeetings)
	say "meetings today"
	delay 1
	say "Your meetings are titled " & myMeetings
end if


Thanks!

Merval

Model: Macbook Pro
AppleScript: 2.1.2
Browser: Firefox 15.0.1
Operating System: Mac OS X (10.6)

Hi merval. Welcome to MacScripter.

You need to keep a list of the times too. :slight_smile: Or perhaps keep a list of the actual sentences you want spoken:

set today to (current date)
set today's time to 0
set tomorrow to today + days
set myMeetings to {}
tell application "iCal"
	set futureEvents to every event of calendar "Meetings" whose start date is greater than or equal to today and end date is less than or equal to tomorrow
end tell
repeat with anEvent in futureEvents
	tell application "iCal" to set {summary:theSummary, start date:theStartDate, allday event:allDayEvent} to anEvent
	
	if (allDayEvent) then
		set theTime to "At some time today"
	else
		set {hours:Eventhour, minutes:Eventminute} to theStartDate
		if (Eventhour > 12) then
			set Eventhour to Eventhour - 12
			set pre to "PM"
		else
			set pre to "AM"
		end if
		if (Eventminute is 0) then set Eventminute to ""
		set theTime to "At " & Eventhour & " " & Eventminute & " " & pre
	end if
	set the end of myMeetings to theTime & " you have a meeting entitled " & theSummary
end repeat

set numberOfMeetings to (count myMeetings)
if (numberOfMeetings is less than 1) then
	say "you do not have any meetings today." using "Alex"
else if (numberOfMeetings is equal to 1) then
	say "you have one meeting today"
	delay 1
	say item 1 of myMeetings
else
	say "you have" & numberOfMeetings & " meetings today"
	delay 1
	repeat with thismeeting in myMeetings
		say thismeeting
		delay 0.5
	end repeat
end if

Edit: Corrected the omission pointed out below by merval.

Thanks!! That works great! I had to add pre to the end of the line:

set theTime to "At " & Eventhour & " " & Eventminute & pre

Works perfectly!

Ah yes. Sorry about that. I use 24-hour time on my own computer. I’ve corrected the script above, including a space before pre to ensure that Eventminute is spoken as a number rather than as a string of digits.

How would I get multiple calendars to be read like, “Home”, “Work” & “Birthdays” ← which is an All-Day event to work with this script? Thanks, I’ve been looking for something simple and clean like this for a while.

Hi soxmonky. Welcome to MacScripter. I received your e-mail about this.

The version of the script below checks all the calendars in the application. But I don’t know if it works, or does anything at all, with subscribed calendars.

With potentially so many events, it could take quite a while to get all the information and identify the relevant events. (Half a minute with my calendars.) I’ve attempted to speed it up a bit by doing a bulk dump of the start dates instead of using the original script’s two-condition ‘whose’ filter.

Your e-mail said the all-day event part in my script above doesn’t work in some way you didn’t specify. On my machine, all-day events run from midnight to midnight in the winter, but from 01:00 to 01:00 in the summer. (I don’t know how it is in other parts of the world.) Since the script ignores events which go past midnight, an 01:00 end could indeed cause a day’s all-day events to be ignored. So in the script below, all-day events are checked to see if they’re only 24 hours long rather than if they end by midnight. HOWEVER, if you’re talking about repeating events ” which is likely in the “Birthdays” calendar you mention ” this script won’t pick up the repeats. A repeating event is a single event which Calendar displays again on later dates. It’s not a series of separate events.

Edit: This script now only checks the Calendars named in its first line.

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 "At some time today"
			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.
			if (theTime is not missing value) then set the end of myMeetings to {theStartDate, theTime & " you have a meeting entitled " & 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 numberOfMeetings to (count myMeetings)
if (numberOfMeetings is 0) then
	set preamble to "You do not have any meetings today."
else if (numberOfMeetings is 1) then
	set preamble to "You have one meeting today"
else
	set preamble to "You have " & numberOfMeetings & " meetings today"
end if
say preamble -- using "Alex"
delay 1
repeat with thisMeeting in myMeetings
	say item 2 of thisMeeting -- using "Alex"
	delay 0.5
end repeat

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

NG
Thanks for your help. I’m new to scripting, I have an Automator Workflow that has several scripts linked together to make a wake up alarm.
Good Morning/Good Afternoon/Good Evening (userName)
Time
Weather
Calendar Events
and lastly play iTunes playlist shuffle.

I can’t do a version of the script that checks all the calendars in the application. I have a lot of calendars, one being an “Automator Cal” that runs all my automated workflows. Which I don’t won’t read in the morning. All I really need is two calendars read out loud. “Home” & “Work”. I think I understand the problem with the All-Day/repeating events and I can work around that. I was using a calendar script I found on http://christianboyce.blogspot.com/2009/09/your-appointments-sir_4544.html?_sm_au_=iVVHWHV3Wn7SHnR4. But it was clunky and it would take quite a while to get all the information and identify the relevant events. Thanks again for all your help!

Ah. Right. All that seems to be needed for that is to change every calendar in the script just above to (every calendar whose name is “Home” or name is “Work”). I’ve edited the post accordingly.

Seems to be error out at - event evnt of calendar cal
(error “Calendar got an error: Can’t get event 180 of calendar 2. Invalid index.” number -1719 from event 180 of calendar 2)

I’ve tried poking around in it and all of a sudden it tells me its Christmas Day or there’s no events at all?! I only have 2 events listed for today.
Is there an issue with the the script just looking at “today”?

Soxmonky

Sorry. My fault. I’ll get onto it.

Later: OK. Done. I’d forgotten I’d have to use the Calendars’ names instead of their indices getting the data the way I did. It now works named calendar by named calendar and you can preset the names at the top of the script.

It really needs a modification to sort the announcements by event time… :rolleyes: I’ll think about it after supper.

OK. It now has that too. It should speak the announcements in appointment order regardless of the order in which they were obtained.

That is amazing. I can’t even begin to imagine how to figure that all out. The only thing I noticed is if you have something scheduled during Noon/12PM it say “12 AM”? Other than that the script is perfect!!! Thanks NG

A hangover from the original script. Not me this time. :slight_smile: Now fixed.

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

::calendar:: 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!

Hi,

just for fun, this is a shorter version of your greeting script.


property weekdayGreetings : {{"Happy Sunday", "Welcome to Sunday Funday", "Today is Sunday bloody Sunday", "I hope you are enjoying your Sunday", "It is Sunday"}, {"Happy Monday!", "It is Monday", "Today is Monday", "Sorry to be the bearer of bad news, but, it is Monday again"}, {"Happy Tuesday!", "It's Taco Tuesday!", "Today is Tuesday"}, {"Happy Wednesday!", "Happy Hump day. The humpty dance is your chance, to do the hump...", "It is Wednesday", "Happy Hump day"}, {"It is Thirsty Thursday!", "Happy Thurday!", "Happy Friday-Eve", "Today is Thursday"}, {"Happy Friday!", " You are all most there, tomorrow's the weekend", "One day to go, tomorrow is Saturday", "It is Friday", "It is Friday"}, {"Happy Saturday", "Huzzuh today is Saturday", "It is Saturday", "I hope you have Great Saturday"}} -- edited according to Nigel's note
property oldrandnum : missing value

--user name
set userName to long user name of (system info)

-- Time of Day
tell (current date) to set {the_hours, currentWeekday} to {its hours, its weekday as integer} -- edited according to Nigel's note
if the_hours is less than 8 then
	set greeting to randomizerGreeting()
	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

set currentday to some item of item currentWeekday of weekdayGreetings

delay 0.3
say currentday

delay 0.3
say "the time right now is " & (do shell script "date +%l' '%M' '%p")

on randomizerGreeting()
	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
	return item randnum of greetings
end randomizerGreeting

Wow, Stefan thats awesome! Thanks that is much cleaner than what I come up with.

Nice script. Think I’d rather have the short user name.

kel1 try…
set userName to short user name of (system info)
Or
set userName to do shell script “whoami”

Also you can try this script I found…


tell application "System Events"
	set full_name to full name of current user as string
	set first_name to first word of full_name as string
end tell
say "Hello " & first_name & ", hey,   whats up?"

Hi.

That should be its hours, otherwise you get 3600.

And the Sunday greetings should be the first in the list at the top of the script. AppleScript weeks start on Sundays.

Of course, thanks.

I tested it on 22:30 local time, so it didn’t catch my eyes at once :wink:

Edit: I changed the script accordingly