I’m puzzled.
As I wanted to test the given script, I ran :
"10/10/2015 00:00:00"
set datum to date result
log datum --> date "samedi 10 octobre 2015 00:00:00"
tell application "Calendar"
activate
tell calendar "Test"
events whose start date is datum
log result
(*event id 5488C5A2-E889-4A7B-9B59-0ED33109C0BD of calendar id 15796FB4-0796-43DD-ACD4-C41067C1012D, event id 416C98D5-E3BF-4BFD-A8DC-1FC7BB31AAD1 of calendar id 15796FB4-0796-43DD-ACD4-C41067C1012D*)
delete (events whose start date is datum)
end tell
end tell
Yes, I am lazy and don’t want to type the long date.
As you see in the comments, the date is correctly built, the script found two events, the delete instruction is correctly issued.
Alas, the two events are always displayed in the calendar.
I ran the script a second time. This time, it reported only one event: (event id 5488C5A2-E889-4A7B-9B59-0ED33109C0BD of calendar id 15796FB4-0796-43DD-ACD4-C41067C1012D) and both events are always displayed.
Of course, when I ran the script a third time, it saw no event and the delete instruction issued an error.
I quitted Calendar then ran this extended version of the script
"10/10/2015 00:00:00"
set datum to date result
log datum --> date "samedi 10 octobre 2015 00:00:00"
tell application "Calendar"
activate
tell calendar "Test"
set theEvents to events whose start date is datum
log result
(*event id 5488C5A2-E889-4A7B-9B59-0ED33109C0BD of calendar id 15796FB4-0796-43DD-ACD4-C41067C1012D, event id 416C98D5-E3BF-4BFD-A8DC-1FC7BB31AAD1 of calendar id 15796FB4-0796-43DD-ACD4-C41067C1012D*)
if theEvents is not {} then
repeat with anEvent in theEvents
log (get properties of anEvent)
delete anEvent
end repeat
end if
end tell
end tell
The events log was :
(date samedi 10 octobre 2015 00:00:00)
tell application “Calendar”
activate
get every event of calendar “Test” whose start date = date “samedi 10 octobre 2015 00:00:00”
(event id 5488C5A2-E889-4A7B-9B59-0ED33109C0BD of calendar id 15796FB4-0796-43DD-ACD4-C41067C1012D, event id 416C98D5-E3BF-4BFD-A8DC-1FC7BB31AAD1 of calendar id 15796FB4-0796-43DD-ACD4-C41067C1012D)
get properties of event id “5488C5A2-E889-4A7B-9B59-0ED33109C0BD” of calendar id “15796FB4-0796-43DD-ACD4-C41067C1012D”
(class:event, status:none, stamp date:date samedi 15 août 2015 11:38:33, allday event:true, recurrence:missing value, end date:date dimanche 11 octobre 2015 00:00:00, url:missing value, start date:date samedi 10 octobre 2015 00:00:00, description:missing value, summary:beurk, location:missing value, sequence:0, uid:5488C5A2-E889-4A7B-9B59-0ED33109C0BD, excluded dates:)
delete event id “5488C5A2-E889-4A7B-9B59-0ED33109C0BD” of calendar id “15796FB4-0796-43DD-ACD4-C41067C1012D”
get properties of event id “416C98D5-E3BF-4BFD-A8DC-1FC7BB31AAD1” of calendar id “15796FB4-0796-43DD-ACD4-C41067C1012D”
(class:event, status:none, stamp date:date samedi 15 août 2015 11:42:10, allday event:true, recurrence:missing value, end date:date dimanche 11 octobre 2015 00:00:00, url:missing value, start date:date samedi 10 octobre 2015 00:00:00, description:missing value, summary:beurk2, location:missing value, sequence:0, uid:416C98D5-E3BF-4BFD-A8DC-1FC7BB31AAD1, excluded dates:)
delete event id “416C98D5-E3BF-4BFD-A8DC-1FC7BB31AAD1” of calendar id “15796FB4-0796-43DD-ACD4-C41067C1012D”
end tell
but the events were always displayed.
When I ran the extended script a second time, the events log was :
(date samedi 10 octobre 2015 00:00:00)
tell application “Calendar”
activate
get every event of calendar “Test” whose start date = date “samedi 10 octobre 2015 00:00:00”
(**)
end tell
So, my understanding is that the script delete the events in ram but the application doesn’t “save” the changes.
I guess that we must issue an instruction to “save” the change but I don’t find which one in the dictionary.
Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) samedi 15 août 2015 12:16:59