I'm really having a hard time understanding how to interact with iCal using the new support for Javascript automation in Yosemite. I'm not too experienced with OOP so that might be where my problem lies.
Could someone help me out with the code for adding a new event to a specified calendar? I can probably reverse engineer it from there to understand how to work with it.
Thanks
UPDATE
Here is the code I am trying..
// -- perform adding to iCal
// -- select "Test" calendar
theCalendar = iCal.calendars.Test;
events = theCalendar.events;
// -- load in the events
stringifiedData = Safari.doJavaScript("localStorage.getItem('theEvents');", {
in: Safari.windows[0].tabs[0]})
// -- parse data back to js object
theEvents = JSON.parse(stringifiedData);
// -- loop through events
for (var key in theEvents) {
var obj = theEvents[key];
// -- set vars
theDate = obj['date'];
theDescription = obj['description'];
theSummary = obj['summary'];
theLocation = obj['location'];
theStartTime = theDate + " " + obj['startTime'];
theEndTime = theDate + " " + obj['endTime'];
// -- create event object
theEvent = iCal.Event({
description: theDescription,
summary: theSummary,
location: theLocation,
startDate: theStartTime,
endDate: theEndTime
});
// -- get the last index event
last = events.length;
// -- insert it into iCal
events.push(theEvent);
}
The error i'm receiving..
Error on line 68: TypeError: undefined is not an object (evaluating 'events.push(theEvent)')
UPDATE
I figured out the issue. I was formatting the dates incorrectly.. they were just strings. So I made sure to turn them into date objects, and I was able to insert successfully using
events[last] = theEvent;