在OSX Yosemite中,我使用新的JavaScript for Automation功能来编写Calendar脚本。我正在尝试搜索日历以查看当前是否有正在发生的事件。
我在AppleScript中这样做了:
set now to current date
every event whose start date < now and end date > now
我注意到AppleScript中有一个专门的AppleScript“日期”对象。事件日志显示如下。关于字符串之前的“日期”修饰符的特别说明,表明这是一个日期对象,而不仅仅是一个字符串。
count every event whose start date < date "Monday, August 11, 2014 at 5:49:46 PM" and end date > date "Monday, August 11, 2014 at 5:49:46 PM" and allday event = false
我试图在AppleScript中这样做:
workCalendar.events.whose({
_and: [
{ startDate: {'<': now} },
{ endDate: {'>': now} }
]
});
但是我为now var设置的任何值都会给出以下错误:
Error -1700: Can't convert types.
我现在尝试了以下值以及所有返回类型转换错误:
calendarApp.includeStandardAdditions = true;
now = calendarApp.currentDate;
now = (new Date());
now = (new Date()).toISOString();
now = $.NSDate.date;
尝试弄清楚我做了什么类型的价值:
firstStartDate = workCalendar.events[0].startDate();
console.log("firstStartDate : " + firstStartDate);
console.log("firstStartDate TO : " + (typeof firstStartDate));
console.log("firstStartDate OS : " + ObjectSpecifier.classOf(firstStartDate));
这导致了事件日志中的内容:
/* firstStartDate : Wed Jun 18 2014 10:30:00 GMT-0700 (PDT) */
/* firstStartDate TO : object */
/* firstStartDate OS : undefined */
答案 0 :(得分:0)
Apple承认这是一个错误 - 从Yosemite Public Beta 3开始,这有效:
now = (new Date());
这有效
firstStartDate = workCalendar.events[0].startDate();
这有效
var currentApp = Application.currentApplication();
currentApp.includeStandardAdditions = true;
now = currentApp.currentDate();