Using AppleScript on Mavericks, I’m trying to “coerce” (I think) an .ics file from the finder to its ‘Calendar Event’ class item. Preferably, it won’t be a droplet that use the Folder Action mechanism.
Ideally, I would like to do something like:
set myItem to the Event referred by thePosixPathToMyFile as Event
But of course, it didn’t work and I just can’t figure out how to do it.
My goal is then to use the Calendar’s applescript dictionary. In short, instead of starting from within the Calendar app, I simply want to start from the HD file.
So, I know the path to my .ics files. This text info can be provide to my applescript as a parameter.
Then, I know it’s a primitive process, but I simply open this file from a Tell Application “Calendar” block.
Since the correct event is now highlighted inside the Calendar app, I guess it will be easy to retrieve this selected UIElement (the Event).
Then, I’ll probably be able to control the content of this found event by using UI scripting !?
Its not exactly what I want because I would of course prefer to use the Calendar applescript dictionary instead of UI scripting… So, I’m just missing a small part which is the actual applescript item/element/class which is inside application/calendars/events.
How can I fill the gap between a file and its representation inside the Calendar app ? OR maybe asked differently, how can I retrieve (and set) a Calendar event by searching its physical file name ??
Thank you Kel1 for your reply ! Yes, that’s what I’m trying to do and I actually succeed with this very simple command:
set myEvent to events in calendar "Work" where uid is "FD5C38C4-62E6-4FE9-A94B-6C8275B86AEC"
. Luckily, this dictionary UID property inside the Calendar app contains the corresponding .ics filename on the disk. In this case, my file is named “FD5C38C4-62E6-4FE9-A94B-6C8275B86AEC.ics”
I’m almost done but I stuck with another problem. Because I need the equivalent thing for the Reminders app (always on Mavericks).
Unfortunately, in Reminders, the dictionary ID property (not UID as in Calendar) seems to have nothing to do with the corresponding filename. Maybe there’s a bug in Reminders and/or in its applescript dictionary !? Or maybe it’s working differently in the Reminders app !?
I’m just unable to retrieve a Reminder by using my ‘key’. Which is: myFilename = (UID & “.ics”)
So, because an applescript command like this is not working in Reminders:
set myReminder to reminders in list "Work" where id is "A526EF6E-DA8F-452C-B66A-E048E30A5D4E"
while the equivalent is working very well in Calendar, I’m still stuck at this point.
If I use the Finder to find the file (using my known .ics filename), then to open the targeted Reminder, I can use UI scripting to control most elements of my Reminder. It works but it’s not very clean…
My other workaround would be to open the .ics file for write access and to work directly inside the file. But I think this solution is not cleaner than UI scripting.
Since I can’t use the Reminder’s dictionary to retrieve my Reminder by using its physical filename, I have no idea how to get satisfaction. Is it possible to use the Document and/or the File classes ? If so, how can I do it ?
Is there another (maybe a low-level hidden) trick that I’m not aware of ?
I’m not a professional applescripter and I need your lights ! Is my “retrieve a Reminder by its filename” operation can be done ??
I remember now. You want to swap out the files in the place where the ics files are stored. I haven’t tried it in Mavericks. It used to be a bit flakey in Jaguar, but now might work.
The part the didn’t work well was in the updating in Calendar. You might find a solution in Mavericks, but I don’t know.