0

This issue all stems from duplicating events from subscribed calendars to a single iCloud calendar I share with someone. When the origin calendar is well structured everything works as expected. My Applescript duplicates the event, and on subsequent runs the duplicate action even updates any changed info in the events (I assume it sees a matching UID and modifies the event instead of recreating it).

I currently have a calendar that sets it's UID to a full blown URL (it also originally had an issue with timezones I remedied, it's why the duplicate includes the start and end dates). This creates issues with duplicating, I believe, because the new events have their UID's have some characters stripped/replaced (/,:) and they stop matching up.

http://domain.com/folder/page.php?eventid=3675 becomes  
http__domain_com_folder_page.php?eventid=3675

First thought was to use a regular expression via sed to create a more standard UID...

repeat with theEvent in theEventsList

    tell theEvent

        ...

        set oldUID to the uid

        set theCommandString to "echo \"" & oldUID & "\" | sed 's:http\\://\\([a-z.]*\\)/\\([a-z0-9]*\\)/[a-z.]*\\?\\([a-z]*\\)\\=\\([0-9]*\\):\\2-\\3\\4@\\1:'" as string

        set newUID to do shell script theCommandString

        ...

    end tell

end repeat

The result is, folder-eventid3675@domain.com. But now I'm stuck. Duplicate, nor make, seems to want to let me create a new event where I include uid in the properties.

make new event at end of calendar sportsCalendar with properties {start date:startTime, end date:endTime, uid:newUID, url:passURL, description:passDescription, summary:passSummary, location:passLocation}

-

duplicate theEvent to end of calendar sportsCalendar with properties {start date:startTime, end date:endTime, uid:newUID}

Both give AppleEvent handler failed, error -10000. At this point I've tried so many variations I'm kinda lost.

At one point I tried setting the original UID to my generated one. And that resulted in a different error, -10006...

Calendar got an error: Can’t set uid of event to "folder-eventid3675@domain.com".

I can live without some of this stuff, but at this point I'm really just curious what I'm doing wrong. Is there any way to fix the UID and duplicate an event from one calendar to another? Thanks!

Edit:
Updating the sed command to be a little cleaner. Sadly it still requires double escaping for a bunch of pieces.
Also adding a bit more code to show how things are constructed.

  • I know it's a somewhat common syntax, but using slashes in sed makes the command far longer than it has to be in many common scenarios due to having to escape all the slashes in a path or URL. Semicolons are preferable. – William T Froggard Jun 7 '15 at 20:34
  • Thanks @Froggard, I'll keep that in mind and try to clear up the syntax a bit. Luckily that doesn't seem to be what's causing issues. – Vagari Jun 8 '15 at 0:21

You must log in to answer this question.

Browse other questions tagged .