Reputation: 943
I have an electron application, and a requirement is to call the mac's api to add related schedules, as shown in the figure:
I want to use swift for development, and then package it into a node addon for electron to call, but I am not very familiar with swift and mac api.
I don't know how to write related swift code and which api to call to complete the function of the above picture.
I tried AppleScript
, but it seems that I can't choose calendar contains freely.
Here is the applescript code to try(unable to meet demand):
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 "Calendar Project"
make new event with properties {summary:"Important Meeting!", start date:theStartDate, end date:theEndDate}
end tell
end tell
Of course, if Objective-C
and AppleScript
can also do it, it is also possible.
Any hints would be helpful. Thanks!
If the above description does not describe the problem well, then I will ask in another way:
What API of macOS
should be called in swift to pop up a Adding a new event
window
Upvotes: 0
Views: 289
Reputation: 61228
The dialog in question is part of Calendar.app and AppleScript is the only way to invoke it, but this is clunky. The best way is to create your own UI and use EventKit to add the event based on the selections in the UI.
Upvotes: 1