Saving todos to my calendar
Disclaimer, you’re going to read the word todo a lot in this post
So it turns out it’s pretty difficult to find a todo app that does exactly what I want. Which is surprising because there are a lot of todo app tutorials. I’ve found a few that looked attractive but then I had to pay for them. I could make a bunch of bad justifications for why I don’t want to pay for a todo app but I think the honest answer is that they sit in the same space for me as a smart watch does. When you have it you definitely feel something improve but I couldn’t for the life of me say what it was.
So that’s what I’m going to be building today. Here’s what I want from it:
- To be unobtrusive
- To maybe save to some sort of history
- To be easy to check and to create new todos
What I’ve settled on is the idea of having a todo app that sits in my menu bar. I have found a few that looked pretty decent but here’s the killer feature I want to include, if I mark an item as done I want it to end up in my calendar for that day. Again, it’s definitely an edge case but it’s one that I seem to come across pretty often.
So let’s get started!
Problem one, I’ve never written swift or actually made a Mac OS app before. I’ve made electron menu bar apps but they are just so heavy. So I’m going to follow a tutorial and see how it goes. I found this one which looks pretty good:
At the beginning of the tutorial I realised I was going to need an icon. I didn’t want to waste time making one so I headed over to flaticon to find a quick free one to use. I accidentally searched for taco instead of todo but I dig the novelty so I’m sticking with it. I’ve already got some branding!
The awesome icon I’m going with was made by Freepik
After getting the menu and status bar button in I’ve got to say I’m already in love with this.
Next step is to add todo items. I’ll start by just adding an “Add todo” button that adds to some array. So far so good!
Next I guess I should show these new todos as buttons or something. I don’t actually think I need the list either so I’ll remove that until I regret my decision later.
After a little messing around, I got a button working that adds “Test todo” buttons that I can click on! This is going pretty well!
I might not always want to have my next todo item be a test so I suppose it’s time to find out how I can get some sort of input going. Minor side note but does anyone else keep accidentally deleting things in XCode? I seem to keep selecting stuff when I didn’t mean to.
It looks like the easiest way to get inputs for now is going to be a text menu item I can enter text into. I say easiest. This monstrosity looks like I’ve definitely done something wrong. But I’ve added a todo (the humor of this has not gotten past me) so that gives me license to move on and never return.
Then I simply retrieved the value from the text field whenever I added a todo and I ended up with this!
Next step I guess is getting rid of the damn things. Which actually wasn’t hard so this paragraph doesn’t get anything more than that. The real meaty bit I want to focus on now is adding these to my calendar. It looks like eventkit is going to be my friend here:
I tried to add an event store thingy that it seems to care about and request permission to access the calendar but then it just said no. Not even a prompt. What I didn’t realise until a good 10 minutes later is that it’s not enough to request the permissions. I need to specify in my apps manifest (in the Apple world called the info.plist) that I want to use the calendar. Which is fine! Because I now have permission! Big success!
I honestly thought at that stage that I would be able to create events but then it failed. And this is where I started banging my head against the wall. It looked like the reason this was happening was because my app was in a sandbox. So I removed that. It then wanted me to sign my app with a developer team. So I added that. I thought I was making great progress! And then all of a sudden… I couldn’t launch my beautiful app anymore!
After Googling for a while, I kind of just gave up and created a new project with everything copied over. If anyone knows why this suddenly stopped working please let me know! This did however work! So I present you with my first todo in my calendar!
A really weird bug I then proceed to encounter is that whenever I launch the app and it asks for permissions, it disables the NSTextView meaning I have to relaunch the app! It turns out that my menu item cannot become the main window so it loses focus which means that means it can’t be edited!
Looks like my little text input will just not do.
Well remember when I added that snarky todo above saying there was probably a better way but I would move one? Well there was. I just had to add an alert!
And with that I have version one working! It’s 11:15pm now so I should probably go to bed but I’m pretty happy with the progress I made today. As a passing thought I did quite enjoy how XCode would just keep telling me what I did wrong. I didn’t really feel lost despite having zero swift experience.
I still need to make this actually package up into an app but if you’re curious what the end result looked like you can find the code from this adventure here: