带有日历和Applescript的多事件警报?

时间:2016-02-08 23:35:30

标签: macos calendar applescript osx-elcapitan

我正在处理一些AppleScript以生成并向我的日历添加大量事件,其中许多事件需要多个警报:a"默认"在上午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中工作所以我完全有可能搞砸了语法,但我已经尝试了从替代语法到在&#之间添加延迟的所有内容34;讲述事件"使用一个作为声音报警,一个作为显示。在这一点上,我想知道我是否可能过于接近它,或者它是否是我不得不与之共存或找到最终结果的怪癖之一。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我已经多次测试过您的脚本,我没有遇到任何问题。我得到了2个警报。我只是做了一些改进来优化脚本本身,但它并没有改变你的逻辑。当然,我没有玩所有参数,但即使有2个闹钟非常关闭(最后一次测试是8:00和8:05),我仍然会收到2个警报!

makeCalendarEvent from {"New Moon", date ("09/02/2016 08:05:00"), 0, "", "", date ("09/02/2016 08:05:00"), true}

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)
set isAllDay to (eventDuration = -1)
if eventDuration = -1 then set eventDuration to 0

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}
        tell newEvent
            if alarmTime is not false then set alarm1 to make new sound alarm at end of sound alarms with properties {trigger date:alarmTime}
            if setDefaultAlarm is true then set alarm2 to make new sound alarm at end of sound alarms with properties {trigger date:(date "08:00 AM" of eventStart)}
        end tell
    end tell
end tell    
end makeCalendarEvent