Clean Your Clipboard!

The clipboard on my iPhone is something that I never really gave much thought to. Copy & Paste, it always just worked when it was there. It took until iOS 3 for it to be introduced, but since then, as a user, I never actually had to worry about it. That was until I installed the iOS 14 beta and I started noticing a new banner appear at the top of my phone whenever I pasted something.

I thought, that’s interesting, my iPhone is telling me when I paste something and where it came from. But then I started noticing it show up immediately after I opened certain apps. Apps that out of convenience would check my clipboard for me to see if there was, for example, a tracking number in there to automatically add it to my parcel tracking list. But that got me thinking, what if that was a password that I recently copied from my password manager? Would I want my post office to see the password to my email account or my company login? And while maybe I can trust my post office to not do something nefarious with what they see in my clipboard, are other apps so trustworthy?

So I decided to look into the feasibility of creating an iOS app that would read the clipboard (when you ask) and clear the clipboard at the tap of a button. After a few DuckDuckGo searches (I don’t Google anymore, more on that another time) and poking around in the Apple developer docs, it turns out its not that hard (literally 1 line of code for each action). So I downloaded the latest XCode beta and started putting together a simple iOS app with 2 buttons and a label, and I ended up with what I’m (for now) calling Clipboard Cleaner.

It is super simple right now, looks like trash, doesn’t even have an icon, but it works. It shows me whats in my clipboard if I’m curious, and clears it for me at the tap of a button. Its a bit of a nuisance since I have to open it before I can clear anything, so I’m thinking of adding some convenience features to make it a little easier to do (like a Siri shortcut, or maybe an iOS 14 widget).

I’m not sure if I’ll put this app up in the App Store or not, it works well enough for me as-is, and it would need a bit more polish before it would even make it through app review. And since I don’t really want to keep it to myself, and since its so simple, I’m making the code public so others can see, maybe learn, and since starting to work at Automattic I’ve been trying to embrace open source. And who knows, maybe someone will want to help add features to it, and it will hopefully get better being out in the open than hidden on my computer.

Check out the code!

But why stop there? I also thought I might want the same thing on my laptop. While other apps can probably sniff the clipboard whenever they want (not just when they’re opened), so its maybe less necessary to have, I wanted take a shot at creating a Mac menu bar app with the same features. Having no experience creating MacOS apps either I jumped back on DDG and found this fantastic article on creating a Mac menu bar app. It took a bit more finessing since the latest XCode beta has a new option for creating apps that the article didn’t mention (I needed to select AppKit from the Life Cycle dropdown), and the clipboard API has a different name, but other than that it wasn’t a huge fuss to put together. And so, Clipboard Cleaner for Mac was born.

Complete with source code!

I’m looking forward to adding more to Clipboard Cleaner (and coming up with a better name), but I’m not sure on what kind of timeline. It feels good to have a small project I can poke at whenever I want, and to have something I made that I can take around with me in my pocket on my phone.

Leave a Reply

%d bloggers like this: