Documentation Archive

Developer

Calendar Scripting Guide

Creating a Calendar

Use the make command to create a new calendar on your Mac, as demonstrated in Listing 3-1 and Listing 3-2. The result of the make command is a reference to the newly created calendar, which can be assigned to a variable for later use in a script. For example, after you create a calendar, a script could add events to it.

APPLESCRIPT

Open in Script Editor

Listing 3-1AppleScript: Creating a new calendar
  1. tell application "Calendar"
  2. set theCalendarName to "Project Calendar"
  3. set theCalendarDescription to "Calendar for top secret Apple project."
  4. set theNewCalendar to make new calendar with properties {name:theCalendarName, description:theCalendarDescription}
  5. end tell
  6. --> Result: calendar 3 of application "Calendar"

JAVASCRIPT

Open in Script Editor

Listing 3-2JavaScript: Creating a new calendar
  1. var Calendar = Application("Calendar")
  2. var calendarName = "Project Calendar"
  3. var calendarDescription = "Calendar for top secret Apple project."
  4. var newCalendar = Calendar.Calendar({name: calendarName, description: calendarDescription}).make()
  5. // Result: Application("Calendar").calendars.at(3)