Macos 如何在OS X Yosemite中使用JS自动化添加iCal事件?

Macos 如何在OS X Yosemite中使用JS自动化添加iCal事件?,macos,applescript,icalendar,javascript-automation,Macos,Applescript,Icalendar,Javascript Automation,我真的很难理解如何使用Yosemite对Javascript自动化的新支持与iCal交互。我对OOP不是很有经验,所以这可能是我的问题所在 有人能帮我把新事件添加到指定日历的代码吗?我可能可以从那里对它进行反向工程,以了解如何使用它 谢谢 更新 这是我正在尝试的代码 // -- perform adding to iCal // -- select "Test" calendar theCalendar = iCal.calendars.Test; events = theCalendar.e

我真的很难理解如何使用Yosemite对Javascript自动化的新支持与iCal交互。我对OOP不是很有经验,所以这可能是我的问题所在

有人能帮我把新事件添加到指定日历的代码吗?我可能可以从那里对它进行反向工程,以了解如何使用它

谢谢

更新

这是我正在尝试的代码

// -- 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);

}
我收到的错误

Error on line 68: TypeError: undefined is not an object (evaluating 'events.push(theEvent)')
更新

我解决了这个问题。我的日期格式不正确。。它们只是线。因此,我确保将它们转换为日期对象,并且我能够使用

events[last] = theEvent;

1.应用程序脚本不是OOP,它是远程过程调用与简单的一级关系查询的组合。试图将其压缩成一种僵化的OO思维模式只会让人困惑和沮丧。2.找到现有的AppleScript示例,并将其作为起点,手动将其转换为JS。我建议JXA团队包括一个简单的自动翻译工具,但他们忽略了我。3.请注意,JXA的功能受损,应用程序不兼容,文档质量差,容易引起误解。AppleScript仍然是唯一支持正确编写应用程序脚本的选项。我使用它的唯一原因是因为我需要发送一个javascript对象并在AppleScript中使用它。基本上,我有一个对象数组,我希望能够在applescript中迭代。我使用编码的URL数据从safari发送,也可以使用localStorage。我将尝试您提到的方法,但是您知道如何将对象数组解析为applescript吗?我必须把它严格化。。但我认为它只支持对象,不支持数组,反之亦然。您应该发布任何代码/示例,以澄清您正在尝试做什么,iCal部分在哪里,以及如何在Safari和AS/JXA之间传递数据。e、 g.不清楚您是通过do JavaScript从AS/JXA调用Safari,还是通过自定义URL方案处理程序从Safari网页调用AS/JXA。