I use ‘Calendar’ under MacOS 10.14.6.
I want to copy and past a calendar event with just different times.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set d1 to date "Monday 9 March 2020 at 14:00:00"
set d2 to date "Monday 9 March 2020 at 15:00:00"
tell application "Calendar"
tell calendar "LK"
set e1 to every event whose summary is "myEvent"
set e1 to item 1 of e1
end tell
duplicate e1 to calendar "LK" with properties {start date:d1, end date:d2}
end tell
myEvent is moved to the new time slot: the event disappears from the original slot and appears in the new one.
However, I do not need to move but to copy. I want the original myEvent to remain where it was.
The dictionary tells that I should get a copy, but it just does not work for me.
Any help would be much appreciated. Thanks in advance. W.
This is because the duplicate command of the Calenar application always works as a move command, not as copy (as with Finder). And there’s nothing to be done about it. But the following does what you need:
set d1 to date "Monday, 9 March 2020 at 12:00:00 AM"
set d2 to date "Monday, 9 March 2020 at 12:00:00 AM"
tell application "Calendar" to tell calendar "LK"
set masterEvent to item 1 of (every event whose summary is "myEvent")
set newEvent to make new event with properties {start date:d1, end date:d2}
tell newEvent
set summary to summary of masterEvent
set allday event to allday event of masterEvent
set status to status of masterEvent
try
set description to description of masterEvent
end try
try
set location to location of masterEvent
end try
try
set url to url of masterEvent
end try
try
set recurrence to recurrence of masterEvent
end try
try
set excluded dates to excluded dates of masterEvent
end try
end tell
end tell
Your suggestion of creating a new event with most of the properties of the original event does work indeed.
However, it has one major limitation : the location.
Indeed, when I enter from within Calendar a proper address as the location in the original event, it is automatically recognised as such and it expands into a map.
On the contrary, when I make a new record with AppleScript copying the original address to the new record, as you suggest, the address on the new record does NOT expand into a map and, therefore, will not give reminders of when to leave.
Do you have an idea on how to solve that issue, KniazidisR?
I can’t understand what strange things are happening with the map showing. It seems as a bug of the software. The map becomes visible and appended only when editing the location manually. Since this is only necessary for visual purposes, I will say the following: adding manually a space to the end of the address and pressing return in the Get Info window makes the map visible. Then it remains visible forever.
After the visualization process, the space can be removed. The map remains.
You may have a look at Shane Stanley’s library CalendarLib.
Shane took care of some oddities so, MAYBE the one which you are facing doesn’t strike when you use the library.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 5 mars 2020 19:36:49
Is this still true? I want to keep the UUID when I move events from one calender to another and I guess recreating them like in your example would fail that requirement.
I am on Catalina now, and original script from OP (post #1) doesn’t work at all. On the Catalina it throws error “Calendar got an error: Events can not be copied”.
As for sharing the UID between 2 events, it is impossible by the definition of UID…
I don’t think so. If I manually export/import an ICS Calendar.app detects duplicates automatically. I mean, that - catching duplicates - is one of the main purposes with UIDs.