getting properties of iCal event in order to move to new time & date

Hello all. I’m having a bugger of a time trying to do anything with existing events in iCal. Simply as a test I’ve created a blank event with the summary “New Event” (default behavior in iCal) in an otherwise blank calendar to try to mess around with. Using Applescript I can find the event, get it’s properties, show the event, etc. However I cannot for the life of me figure out how to modify it’s properties, or even place the properties into variables to use to create a new event with the same settings on a different time/date.

I’ve tried modifying the list that is created by getting the properties of the event, just getting individual properties of the event into a variable. Heck, I can’t even check to see if the specific property exists using a variable for the event!

Anyway, here is some sample code I’ve been messing with to try to figure this out. Any insight would be greatly appreciated. BTW, I’m using 10.9 Mavericks…


set theEvent to {}
set workRecord to {}
set newDate to "12/07/2013"
set newTime to "12:00 PM"
set workingDate to newDate & " " & newTime
set workingDate to date workingDate

tell application "Calendar"
	tell calendar "Default"
		set theEvent to events whose summary contains "Event"
		set theEventProperties to properties of theEvent
		
		--if exists (stamp date of theEvent) then          --the if statement errors out using theEvent variable, but works fine with the search used to define theEvent
			set theStampDate to stamp date of event whose summary contains "Event"
			return theStampDate
		--end if
	end tell
end tell

Hi,


events whose summary contains

returns a list of objects as the plural events implies
Either you use a repeat loop to iterate thru the found events


tell application "Calendar"
	tell calendar "Default"
		set filteredEvents to events whose summary contains "Event"
		repeat with theEvent in filteredEvents
			set theEventProperties to properties of theEvent
			-- do something with theEventProperties
		end repeat
	end tell
end tell

or you could search for the first event which matches the criteria


tell application "Calendar"
	tell calendar "Default"
		try -- if no event is found an error is thrown
			set theEvent to 1st event whose summary contains "Event"
			set theEventProperties to properties of theEvent
			-- do something with theEventProperties
		end try
	end tell
end tell

Hi GAK711,

For one, this part:

set theEvent to events whose summary contains "Event" -- a list
set theEventProperties to properties of theEvent

The first line is a list. You cannot get properties of the list. You can:

set theEventProperties to properties of events whose summary contains "Events"

I didn’t test it but it should return a list of properties of all events whose summary contains “Events”. If not, write back.

gl,
kel

Hello Kel, thank you for the response.

Yes, I have gotten that far. After I end up with the list of properties from

set theEventProperties to properties of events whose summary contains "Events"

I can’t change anything in that list.

Maybe just take this one piece at a time…
I’m trying to get one property - stamp date - and it’s erring out.


tell application "Calendar"
	tell calendar "Default"
		if exists (stamp date of events whose summary contains "Event") then  --returns true
			set theStampDate to stamp date of event whose summary contains "Event"
			return theStampDate
		end if
	end tell
end tell

as mentioned above, either

objects of something whose -- plural, returns a list

or

[index] object of something whose -- singular, returns one object or throws an error 

index can be

integer (st | nd | rd | th )
( first | second | third | fourth | fifth | sixth | seventh | eighth | ninth | tenth ),
( last | front | back ),
some

Stefan’s second script is an example of getting a single event (the first that matches the criteria). Then you can set the date stamp with something like this:

set date_stamp to (current date)
tell application "Calendar"
	tell calendar "Default"
		try -- if no event is found an error is thrown
			set theEvent to 1st event whose summary contains "Event"
			set stamp date of theEvent to date_stamp
		end try
	end tell
end tell

I’m not sure but I think that for some events you may not be able to set the date stamp.

gl,
kel

:slight_smile:

Well I’ll be…

Thank you so much for your help! I can now manipulate start date (or any other changeable property) at will on my iCal events!

Hopefully I’ll be able to return the favor to some folks now…

Leveraging off the information in this post, I altered it to create events to remind me when to change my Invisalign…

tell application "Calendar"
	activate
	set theCount to 13
	set theDate to date "Sunday, December 1, 2024 at 9:00:00 PM"
	set theEndDate to date "Wednesday, January 1, 2025 at 9:00:00 PM" --this date doesn't matter, just has to be a real date
	tell calendar "Invisalign"
		repeat 26 times
			set theEndDate to theDate + 4
			make new event with properties {description:"Change Invisalign " & theCount, summary:"Change Invisalign to Set " & theCount, start date:theDate, end date:theEndDate}
			set theDate to theDate + 60 * 60 * 96
			set theCount to theCount + 1
		end repeat
	end tell
	reload calendars
end tell

this creates an event every four days and increments the event to match which set of Invisalign sets I need on a specific date.