Open alexrabin opened 7 months ago
For anyone that comes across this project and wants to know how to incorporate it into their own project, EventKit only works on macOS and in order to use it, you have to run your script in iTerm or Warp in order to ask for Calendar access. Running your script from VS Code or Terminal will not work.
native
folder and all the files inside of the src
folder into your projectnpm i node-mac-permissions ffi-napi
npm i ref-array-napi -D
cd
into the native folder and run swift build
to build the Swift binarynpm run dev
| npm run start
or whateverFirst check if you have permissions:
const permissions = await EventKitJS.checkPermissions();
// permissions is an object that returns {calendar: boolean, reminders: boolean}
// I was unable to get reminders to work
Once you have gotten the correct permissions, you can now access the events on a calendar:
const eventStore = new EventKitJS.EventStore();
const dateNow = new Date();
const dateFuture = new Date();
dateFuture.setHours(23, 59);
// As an example, this retrieves events from the current time to the end of the current day
const predicate = eventStore.predicateForEvents(dateNow, dateFuture);
const events = eventStore.events(predicate);
Have fun using the events :)
This looks like an awesome project! Would love to know how to implement this into my project :)