Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this still maintained? #5

Open
alexrabin opened this issue Mar 18, 2024 · 1 comment
Open

Is this still maintained? #5

alexrabin opened this issue Mar 18, 2024 · 1 comment

Comments

@alexrabin
Copy link

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

@alexrabin
Copy link
Author

alexrabin commented Mar 19, 2024

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
  1. cd into the native folder and run swift build to build the Swift binary
  2. You're gonna have to fix all the typescript formatting issues on your own if you encounter them
  3. 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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant