Creating an Event
Use the make
command to create events on a given calendar. Listing 8-1 and Listing 8-2 demonstrate how to do this by creating a 1-hour meeting event, tomorrow, on a project calendar. The result of each example is a reference to the newly created event.
APPLESCRIPT
set theStartDate to (current date) + (1 * days)
set hours of theStartDate to 15
set minutes of theStartDate to 0
set seconds of theStartDate to 0
set theEndDate to theStartDate + (1 * hours)
tell application "Calendar"
tell calendar "Project Calendar"
make new event with properties {summary:"Important Meeting!", start date:theStartDate, end date:theEndDate}
end tell
end tell
--> Result: event id "10D0A87A-3B92-474B-8365-D5434280AA31" of calendar id "CDF2EA89-AE82-44C0-B1B6-449128A5E151" of application "Calendar"
JAVASCRIPT
var app = Application.currentApplication()
app.includeStandardAdditions = true
var Calendar = Application("Calendar")
var eventStart = app.currentDate()
eventStart = eventStart
eventStart.setDate(eventStart.getDate() + 1)
eventStart.setHours(15)
eventStart.setMinutes(0)
eventStart.setSeconds(0)
var eventEnd = new Date(eventStart.getTime())
eventEnd.setHours(16)
var projectCalendars = Calendar.calendars.whose({name: "Project Calendar"})
var projectCalendar = projectCalendars[0]
var event = Calendar.Event({summary: "Important Meeting!", startDate: eventStart, endDate: eventEnd})
projectCalendar.events.push(event)
event
// Result: Application("Calendar").calendars.whose({_match: [ObjectSpecifier().name, "Project Calendar"]}).calendars.at(0).events.byId("D7D2AC03-C5DF-4415-B6E3-0243E0314808")
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-09-13