我正在制作一些AppleScript来生成并向我的日历添加大量事件,其中许多事件需要多个警报:上午9点的“默认”警报和存储在变量中的第二个警报 . 但是,当我运行它时,实际创建的警报是不一致的:有时我得到一个警报,有时是另一个,有时两个 .
这是处理与Calendar和测试用例100%交互的子 .
on makeCalendarEvent from {eventTitle, eventStart, eventDuration, eventDescription, eventURL, alarmTime, setDefaultAlarm}
--duration (in hours, 0= instantaneous, -1= all day)
--alarmTime (date or false)
--defaultAlarm 9AM (coded here for the moment, may move the parameter up to the var block at some point)
if eventDuration = -1 then
set isAllDay to true
set eventDuration to 0
else
set isAllDay to false
end if
tell application "Calendar"
tell calendar "test"
set newEvent to make new event at end with properties {summary:eventTitle, start date:eventStart, end date:(eventStart + (eventDuration * hours)), allday event:isAllDay, description:eventDescription, url:eventURL}
if alarmTime is not false then
tell newEvent
set alarm1 to make new sound alarm at end of sound alarms with properties {trigger date:alarmTime}
end tell
end if
if setDefaultAlarm is true then
tell newEvent
set alarm2 to make new sound alarm at end of sound alarms with properties {trigger date:(date "09:00 AM" of eventStart)}
end tell
end if
end tell
end tell
end makeCalendarEvent
makeCalendarEvent from {"New Moon", date ("Monday, February 8, 2016 at 09:39:00"), 0, "", "", date ("Monday, February 8, 2016 at 09:39:00"), true}
我不经常在Applescript中工作所以我完全有可能搞砸了语法,但是我尝试了从替代语法到在“告诉事件”之间添加延迟以及使用一个作为声音警报的所有内容 . 一个作为显示器 . 在这一点上,我想知道我是否可能过于接近它,或者如果这是我将不得不忍受的那些怪癖之一或者找到最终的结果 .
非常感激任何的帮助 .
1 回答
我已经多次测试过你的脚本了,我没有问题 . 我得到了2个警报 . 我只是做了一些改进来优化脚本本身,但它并没有改变你的逻辑 . 当然,我没有玩所有参数,但即使有2个警报非常关闭(最后一次测试是8:00和8:05),我仍然得到2个警报!