Documentation Archive


Calendar Scripting Guide

Adding an Alarm to an Event

Calendar events can contain alarms that display messages, send emails, and play sounds. Listing 11-1 and Listing 11-2 show how to add alarms to an event. Each example adds two alarms—a message alarm and a message-with-sound alarm.


Open in Script Editor

Listing 11-1AppleScript: Adding alarms to an event
  1. tell application "Calendar"
  2. tell calendar "Project Calendar"
  3. set theEvent to (first event where its summary = "Important Meeting!")
  4. tell theEvent
  5. -- Add a message alarm
  6. make new display alarm at end of display alarms with properties {trigger interval:-5}
  7. -- Add a message with sound alarm
  8. make new sound alarm at end of sound alarms with properties {trigger interval:-5, sound name:"Sosumi"}
  9. end tell
  10. end tell
  11. reload calendars
  12. end tell


Open in Script Editor

Listing 11-2JavaScript: Adding alarms to an event
  1. var app = Application.currentApplication()
  2. var Calendar = Application("Calendar")
  3. var projectCalendars = Calendar.calendars.whose({name: "Project Calendar"})
  4. var projectCalendar = projectCalendars[0]
  5. var events ={summary: "Important Meeting!"})
  6. var event = events[0]
  7. // Add a message alarm
  8. var displayAlarm = Calendar.DisplayAlarm({triggerInterval: -5})
  9. event.displayAlarms.push(displayAlarm)
  10. // Add a message with sound alarm
  11. var soundAlarm = Calendar.SoundAlarm({triggerInterval: -5, soundName: "Sosumi"})
  12. event.soundAlarms.push(soundAlarm)
  13. Calendar.reloadCalendars()