Documentation Archive

Developer

Calendar Scripting Guide

Finding a Calendar

You can locate a calendar by searching for its name, as demonstrated in Listing 4-1 and Listing 4-2. The result of each example is a reference to the found calendar, which has been assigned to a variable for potential use later in a script.

APPLESCRIPT

Open in Script Editor

Listing 4-1AppleScript: Finding a calendar matching a specific name
  1. tell application "Calendar"
  2. set theCalendarName to "Project Calendar"
  3. set theCalendar to first calendar where its name = theCalendarName
  4. end tell
  5. --> Result: calendar id "80CCA5CA-808B-43B3-936D-4D9D7B33B516" of application "Calendar"

JAVASCRIPT

Open in Script Editor

Listing 4-2JavaScript: Finding a calendar matching a specific name
  1. var Calendar = Application("Calendar")
  2. var calendarName = "Project Calendar"
  3. Calendar.calendars.whose({name: "Project Calendar"})
  4. // Result: Application("Calendar").calendars.whose({_match: [ObjectSpecifier().name, "Project Calendar"]})