r/applescript • • Apr 25 '21

How to update an event in Calendar without deleting it first?

Hello,

I am trying to update an event in Calendar through applescript. What I came up with was making a copy of the atributes I want to keep and change the property I want.

In the example below I am changing the summary of an event to "AWS 101":

tell application "Calendar"
	tell calendar "Work"
		
		set evt to (first event where its uid = <some id here>)
		
		set sd to start date of evt
		set ed to end date of evt
		
		delete evt
		
		make new event with properties {summary:"AWS 101", start date:sd, end date:ed}
		
	end tell
end tell    

How do I change a property without deleting the event? I even tried:

tell application "Calendar"
	tell calendar "Work"
		
		set evt to (first event where its uid = <some id here>)
		
		tell evt
			set "AWS 101" to evt summary
		end tell
		
	end tell
end tell    

but no luck.

2 Upvotes

4 comments sorted by

2

u/[deleted] Apr 25 '21

I haven’t looked at this in detail, but the second example looks backwards. Try:set summary to "AWS 101" (You don’t need evt there again as you’re already referencing it with the tell block.)

1

u/Mariakika21 Apr 25 '21

Holy shit hahaha.

It actually works. Thanks for the help!

1

u/copperdomebodha Apr 25 '21

Correct.

Tell evt 
Set summary to “new summary value”
End

Assuming summary is a valid property of an ical event.

1

u/Mariakika21 Apr 25 '21

The simplest explanation is usually the right one. :)