【问题标题】:Multiple Event Alarms with Calendar and Applescript?带有日历和 Applescript 的多个事件警报?
【发布时间】:2016-02-08 23:35:30
【问题描述】:

我正在编写一些小程序来生成大量事件并将其添加到我的日历中,其中许多事件需要多个警报:上午 9 点的“默认”警报和存储在变量中的第二个警报。但是,当我运行它时,实际创建的警报是不一致的:有时我会收到一个警报,有时会收到另一个警报,有时会同时收到两个警报。

这是处理 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 中工作,所以完全有可能我只是搞砸了语法,但我已经尝试了所有方法,从替代语法到在“告诉事件”之间添加延迟再到使用一个作为声音警报和一个显示。在这一点上,我想知道我是否离它太近了,或者它是否是我将不得不忍受的那些怪癖之一,或者找到一个终点。

任何帮助将不胜感激。

【问题讨论】:

    标签: macos calendar applescript osx-elcapitan


    【解决方案1】:

    我已经对您的脚本进行了多次测试,但没有遇到任何问题。我得到了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
    

    【讨论】:

    • 此时我认为问题实际上是网络。如果我创建并写入本地日历,一切正常,如果我写入网络(在我的情况下为 iCloud)日历,我仍然会收到随机警报。知道这一点并且您检查我的代码对我来说已经绰绰有余。感谢您的测试,我会尽量记住缩短的语法。
    猜你喜欢
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多