2016-02-08 41 views
0

我正在編寫一些applescript來爲我的日曆生成和添加大量事件,其中很多需要多個警報:上午9點的「默認」警報和存儲在變量中的第二個警報。但是,當我運行它時,實際創建的警報不一致:有時會發出一次警報,有時會發生另一次警報,有時會發生兩次警報。帶日曆和Applescript的多事件警報?

以下是處理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的工作,所有的時候所以它是完全有可能的,我只是搞砸了語法,但我已經試過一切從替代語法來增加之間的「講事件」延遲將其中一個用作聲音報警器,另一個用作顯示器。在這一點上,我想知道我是否可能會太靠近它,或者如果這是我將不得不忍受的一些怪癖,或者找到一個結果。

任何幫助將不勝感激。

回答

0

我已經測試過幾次你的腳本,我沒有問題。我得到2個警報。我只是做了一些改變來優化腳本本身,但它並沒有改變你的邏輯。當然,我並沒有使用所有的參數,但即使有兩個非常關閉的報警(最後一次測試是早上8點和上午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 
+0

在這一點上我覺得** **的問題實際上是網絡。如果我創建和寫入本地日曆一切正常,如果我寫入網絡(在我的情況下,iCloud)日曆,我仍然會得到隨機報警。知道這一點,並且檢查我的代碼對我來說已經足夠讓我完成一個不痛苦的解決方法。感謝您的測試,我會盡力記住下面的短語。 –