reminders-cli icon indicating copy to clipboard operation
reminders-cli copied to clipboard

[Feature request] Add listing flags / dates / notes / URLs in JSON format

Open wkoszek opened this issue 4 years ago • 4 comments

How hard could it be to add listing not only a title of a task but also all the other auxiliary parameters attached to an item?

image

My dream come true: reminders -f json show TODO gives me a JSON dump of everything on the TODO list.

How much work would it be?

wkoszek avatar Jan 04 '21 05:01 wkoszek

I'm not sure if all the metadata is accessible in the API as it is today, but otherwise I think it would be do-able

keith avatar Jan 04 '21 19:01 keith

@keith Would you be willing to add a bug bounty label for this? I'd be willing to donate $25 to someone who could explore this.

wkoszek avatar Jan 10 '21 20:01 wkoszek

Any quick guide on how that works? I've never done that with one of my issues

keith avatar Jan 12 '21 02:01 keith

I'd just make a gold label with $25 in it. E.g.: https://github.com/Kapeli/Dash-User-Contributions/issues/2014

wkoszek avatar Jan 12 '21 05:01 wkoszek

Dumb question: Would this enable me to wrap reminders-cli inside a non-Swift application ?

fbaube avatar Dec 18 '22 22:12 fbaube

Do you mean this specific feature request or the tool in general? Either way likely no, unless you can bridge to objective-c in whatever language you're trying to use, or you might be able to shell out to this CLI

keith avatar Dec 18 '22 22:12 keith

Ah sorry, i meant: the reminders-cli app in general. I'd line to be able to invoke it from Go and capture the output. I wouldn't think it would pose any particular problems.

fbaube avatar Dec 18 '22 23:12 fbaube

I'm not sure if all the metadata is accessible in the API as it is today, but otherwise I think it would be do-able

Looks like main.swift calls into CLI.swift, which calls into Reminders.swift, which uses EKEventStore from EventKit:

  • https://developer.apple.com/documentation/eventkit
  • https://developer.apple.com/documentation/eventkit/ekeventstore
  • https://developer.apple.com/documentation/eventkit/ekeventstore/1507128-calendars
    • calendars(for:): Identifies the calendars that support a given entity type, such as reminders or events.

It looks like getCalendars() currently filters it so we can only access 'reminder calendars' that are modifiable:

  • https://github.com/keith/reminders-cli/blob/main/Sources/RemindersLibrary/Reminders.swift#L306-L309
  • https://developer.apple.com/documentation/eventkit/ekcalendar/1507068-allowscontentmodifications

reminders() uses Store.predicateForReminders() + Store.fetchReminders() to fetch all of the reminders for the given EKCalendar, which returns an array of EKReminders:

  • https://developer.apple.com/documentation/eventkit/ekeventstore/1507086-predicateforreminders
    • Creates a predicate to identify all reminders in a collection of calendars.

  • https://developer.apple.com/documentation/eventkit/ekeventstore/1507500-fetchreminders
    • Fetches reminders matching a given predicate.

It looks like EKReminder directly allows reading the priority, start date, due date, whether it's completed, and the date it was completed; but it also inherits from EKCalendarItem which allows reading the title, location, creation/modified date, timezone, url, notes, attendees (may not be relevant to a reminder), alarms, recurrence rules, etc:

  • https://developer.apple.com/documentation/eventkit/ekreminder
    • A class that represents a reminder in a calendar.

  • https://developer.apple.com/documentation/eventkit/ekcalendaritem
    • An abstract superclass for calendar events and reminders.

Skimming through the UI in the Reminders app, that looks like it covers pretty much if not all of the fields I can see on a reminder (maybe not images.. but I suspect that may be 'hidden' in the notes/similar objects maybe?); so this issue definitely seems plausible to complete?


A quick google for Swift JSON handling lead me to the following:

  • https://developer.apple.com/swift/blog/?id=37
    • Working with JSON in Swift

  • https://developer.apple.com/documentation/foundation/nsjsonserialization
    • An object that converts between JSON and the equivalent Foundation objects.

  • https://developer.apple.com/documentation/foundation/jsonserialization

    • An object that converts between JSON and the equivalent Foundation objects.


Looks like the 'Building Manually' instructions are pretty straightforward to follow, with 1 minor tweak:

  • https://github.com/keith/reminders-cli#building-manually
  • https://github.com/keith/reminders-cli/pull/52

We can also run it in debug mode with swift run reminders (eg. swift run reminders --help)


Edit: I've been hacking away at this this afternoon and have a mostly implemented prototype. Will clean it up and put up a PR shortly.

0xdevalias avatar Jan 03 '23 03:01 0xdevalias

Just put up a PR to resolve a chunk of the above. It adds a new export-all command that outputs Reminders as JSON. It adds a bunch of extra fields that I identified, but there were still some (eg. flag) that I didn't figure out/find a way to access through the SDK during my brief research today. There are still a couple of tiny TODO/improvement things i'd like to do, but it's usable/testable in it's current state.

  • https://github.com/keith/reminders-cli/pull/53

0xdevalias avatar Jan 03 '23 08:01 0xdevalias

I believe done in https://github.com/keith/reminders-cli/pull/55/

keith avatar May 22 '23 18:05 keith