Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Change iCal attendee attendance status via script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Change iCal attendee attendance status via script
Authored by: ephramz on Mar 29, '07 10:23:29PM
I've modified this script to keep a running tally of the different categories of attendees (accepted, undecided, declined, unknown, and total) which it recalculate each time the script is used. It seems to mees up the description (notes)) text a bit (destroys carriage returns) but otherwise works well to see how many people you invited to an event and how many are coming. Forget evite, use this!


tell application "iCal"
	-- Choose the calendar
	activate
	set cal_future_events to {}
	repeat with this_cal in every calendar
		copy (every event in this_cal whose (start date is greater than the (current date))) to the end of cal_future_events
	end repeat
	
	
	-- Look through the events and choose those in the next the_number_of_days
	set the_number_of_days to 5
	set the_event_list to {}
	set the_name_list to {}
	repeat with the_events in cal_future_events
		repeat with the_event in the_events
			if the (count of the attendees of the_event) is greater than 0 then
				set the end of the_event_list to the_event
				set the end of the_name_list to the summary of the_event & " (" & the start date of the_event & ")"
			end if
		end repeat
	end repeat
	-- If there are no events in the_number_of_days days with attendees, give up
	if (count of the_name_list) is 0 then
		display dialog "No nearby events found." buttons {"OK"} default button 1
		return
	end if
	-- Otherwise, pick the event
	set the_name to (choose from list (the_name_list) with prompt "Choose the event:") as string
	set the_event to null
	-- Note that we're including the name & date for readability, and the uid for specificity
	-- Kind of ugly, but no way to hide the UID when using the "choose" syntax that I know of
	repeat with this_event in the_event_list
		if the_name is equal to the (summary of this_event & " (" & the start date of this_event & ")") then
			set the_event to this_event
		end if
	end repeat
	-- If the user hit cancel, the event is null, so give up
	if the_event is null then return
	
	repeat with att in attendees of the_event
		if not (display name of att exists) then set display name of att to email of att
	end repeat
	-- Get the list of attendees; in this case, we're assuming display name is unique
	set attendee_list to the display name of every attendee of the_event as list
	set the_attendees to choose from list attendee_list with prompt "Choose the attendee(s) to change the status for:" with multiple selections allowed
	-- Find the one we picked
	set naccepted to 0
	set ndeclined to 0
	set nundecided to 0
	set nunknown to 0
	repeat with the_attendee in every attendee of the_event
		if the display name of the_attendee is in the_attendees then
			set the_old_status to the participation status of the_attendee
			-- If we got some random status that isn't listed, let the user know
			if the_old_status as string is not in {"unknown", "accepted", "declined", "undecided"} then
				set the_extra_prompt to "
				(was " & the_old_status & ")"
			else
				set the_extra_prompt to ""
			end if
			-- Either way, try to pre-select the current status using "default"
			set the_new_status to choose from list {"unknown", "accepted", "declined", "undecided"} 
				with prompt "Choose new status for " & display name of the_attendee & 
				":" & the_extra_prompt default items {the_old_status as string}
			-- Convert the status-as-applescript-constant to status-as-string
			if the_new_status is not false then
				set the_new_status to the_new_status as string
				if the_new_status is equal to "unknown" then set the_new_status to unknown
				if the_new_status is equal to "accepted" then set the_new_status to accepted
				if the_new_status is equal to "declined" then set the_new_status to declined
				if the_new_status is equal to "undecided" then set the_new_status to undecided
				if email of the_attendee is "nomail" then set email of the_attendee to (first word of ((display name of the_attendee) as string)) & "_" & (last word of ((display name of the_attendee) as string)) & "_has@no_email.com"
				set the participation status of the_attendee to the_new_status
				log ((participation status) of the_attendee) as string
				log the_attendee
				log (display name of the_attendee) as string
				log (email of the_attendee) as string
			end if
		end if
		set the_new_status to participation status of the_attendee
		if the_new_status as text is equal to "unknown" then
			set nunknown to nunknown + 1
		else if the_new_status as text is equal to "accepted" then
			set naccepted to naccepted + 1
		else if the_new_status as text is equal to "declined" then
			set ndeclined to ndeclined + 1
		else if the_new_status as text is equal to "undecided" then
			set nundecided to nundecided + 1
		end if
	end repeat
	-- Apparently, unless you create and then remove an attendee, iCal may think nothing has happened
	tell the_event
		set desc to (description as text)
		if (the first paragraph of desc) as text is "Current tallies of attendedees:" then
			set desc to paragraphs 9 through -1 of desc
		end if
		set description to "Current tallies of attendedees:
	" & naccepted & "	accepted
	" & nundecided & "	undecided
	" & ndeclined & "	declined
	" & nunknown & "	unknown
	-------------------------
	" & nunknown + naccepted + nundecided + ndeclined & "	total

" & desc
		set fake_attendee to (make new attendee at the beginning of the attendees of the_event)
		delete the fake_attendee
	end tell
end tell


[ Reply to This | # ]