anthdono / eventkit-js

Prototyping a Node.js wrapper for Apple's EventKit framework.
GNU General Public License v3.0
3 stars 1 forks source link

Is this still maintained? #5

Open alexrabin opened 7 months ago

alexrabin commented 7 months ago

This looks like an awesome project! Would love to know how to implement this into my project :)

alexrabin commented 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.

Here is what I did to get the project set up:

  1. Clone this repo to your machine
  2. Copy the native folder and all the files inside of the src folder into your project
  3. Make sure to install the following dependencies:
    npm i node-mac-permissions ffi-napi
    npm i ref-array-napi -D
  4. cd into the native folder and run swift build to build the Swift binary
  5. You're gonna have to fix all the typescript formatting issues on your own if you encounter them
  6. Run your script: npm run dev | npm run start or whatever

How to access your events:

First 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 :)