我尝试创建一个run函数。成功了!
示例脚本。
#!/usr/bin/osascript
function run(command_line_parameters){
command_line_parameters = JSON.parse(command_line_parameters)
calendar_name = command_line_parameters['calendar']
summary = command_line_parameters['summary']
starts = command_line_parameters['starts']
start_date_time = starts.split(' ')
start_date = start_date_time[0]
start_time = start_date_time[1].split(':')
ends = command_line_parameters['ends']
end_date_time = ends.split(' ')
end_date = end_date_time[0]
end_time = end_date_time[1].split(':')
var app = Application.currentApplication()
app.includeStandardAdditions = true
var Calendar = Application("Calendar")
var eventStart = new Date(start_date)
eventStart.setHours(start_time[0])
eventStart.setMinutes(start_time[1])
eventStart.setSeconds(0)
var eventEnd = new Date(end_date)
eventEnd.setHours(end_time[0])
eventEnd.setMinutes(end_time[1])
eventEnd.setSeconds(0)
console.log(calendar_name,summary,starts,ends)
var projectCalendars = Calendar.calendars.whose({name: calendar_name})
var projectCalendar = projectCalendars[0]
var event = Calendar.Event({summary: summary, startDate: eventStart, endDate: eventEnd})
projectCalendar.events.push(event)
event
}
示例运行。
./create-event.js '{"calendar":"BD2L-AT", "starts":"2018-12-16 09:00", "ends":"2018-12-16 13:43", "summary":"Created from command line"}'