I have been struggling with this for a while now and would appreciate some help!
I have an iCal calendar which I populate via an applescript from email messages. This works fine, but when an event is updated, I would like my script to delete any existing events of the same summary.
tell application "iCal"
tell calendar "MyCalendar"
set theEvent to first event whose summary contains "Job: 18031"
if exists theEvent then
delete theEvent
end if
end tell
end tell
The above script works perfectly if their is an event with “Job: 18031” but if not I get an AppleScript error: The variable theEvent is not defined.
if no event is found with the boolean filter, the variable won’t be defined at all.
And if some event is found, it logically exist
You can delete the first found event easier with
tell application "iCal"
tell calendar "MyCalendar"
delete (first event whose summary contains "Job: 18031")
end tell
end tell
Note: consider, that the order of events is not sorted in any way