I left off with the rem
command-line app parsing the command-line arguments and stubbed out the functions to handle each command. I’m going to finish up the app by fleshing out each command function.
Before working on the handler functions, I want to do one more thing. I want to check that my command-line arguments actually specify an actual reminder list (calendar) and reminder id (index).
The EKCalendarItem
has two identifier properties: calendarItemIdentifier
and calendarItemExternalIdentifier
. At first thought, it would be a good idea to use one of those properties as the reminder id. However, both identifier properties return a GUID, which is great for programming purposes, but not so ideal for a command-line app. So, reminder id will be a simple integer to represent the reminder position in the reminder list.
Basically, we want to check the reminder list name specified and compare it to the known names in the calendars
dictionary. If the name is valid, then we check to see if the specified reminder id is within the index range of the reminder array for a given reminder list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
The ls
command allows the calendar
and reminder_id
variables to be nil
. Other than that, we use the arguments to assign values to the variables calendar
and reminder
.
Displaying Reminders
Before implementing each function, I need some special characters for displaying the reminders. Let’s take another look at the pass output:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
It turns out that pass
uses the file system to store everything. To get the nicer output, it uses a program called tree, which prints out file-system hierarchies. We could hack something that writes out to the file-system, then use tree
to display it, but that’s overkill. Our reminders aren’t stored in a tree; they’re only two levels deep: the reminders and their list.
Looking at the pass
output, there are three “special” strings: “│ “, “├──”, “└──”. Looking at the tree
source, I found the unicode encodings for them. But, I’m cheating and just cutting and pasting into the code.
1 2 3 4 |
|
Now, there are two things to consider: 1. The last calender and reminder need to use the corner character. 2. The reminders of the last calendar don’t have the vertical bar. For expediency’s sake, I’m using two functions for output. One for calendars and one for reminders.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Listing Reminders
Now, the listReminders
function is suppose to handle two cases: reminders in a specific reminder list or all reminders. The actually calls to printCalendarLine
and printReminderLine
will be handled by listCalendar
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Trying it out, it gives us this output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Looks good, but one more tweak. All the other commands use a reminder_id to identify which reminder to use. Recall, that I’m just printing a simple integer index as the reminder_id. printReminderLine
and listCalendar
change to this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Removing a Reminder
Removing a reminder is a simple call to removeReminder:commit:error:
to the event store.
1 2 3 4 5 6 7 8 |
|
Show a Reminder Details
Showing a reminder is a little verbose, but pretty straight-forward. The only catch is using an NSDateFormatter
instance to display the date properties of a reminder. The reminder properties I chose to display are: title, calendar (reminder list) name, creation date, last modification date (if different than creation date), start date (if set), due date (if set), and notes (if set).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Completing a Reminder
Completing reminder is a simple matter of setting the completed property to YES and saving it.
1 2 3 4 5 6 7 8 9 |
|
That’s it. Now I have a simple command-line utility to let me list, view, remove and complete reminders. The project is up on Github. Feel free to use and give me your feedback. I have plans to extend rem
, check the issues for what’s in the queue.