Telltail: Universal Clipboard for Text

Published on 14 March 2023

Find the repository here.


Apple Handoff has a neat feature called Universal Clipboard. With it, you can copy a text from one Apple device and paste onto another. Like many, all my devices aren’t of Apple’s, and like them I too am using an intermediary like WhatsApp or sometimes a file sharing tool. This is so common to do that even WhatsApp recognised it and advertised it as a feature.

This is my attempt to solve it.

Before I start telling you about it:

With that out of the way, we can observe that there are three parts to this problem:

  1. The devices should be able to somehow identify each other, securely and privately
  2. We need to create a base platform over which we can send and receive texts
  3. We need to make it convenient, otherwise we won’t use it

Tailscale already handles first point for us, so we need to work on the latter two.

Let’s Start Simple

The easiest way I could think to achieve this is to make a website whose backend will store the text. I started with making a home page / where I can view and change the text. And as I already knew that I would use iOS Shortcuts app down the line (Shortcuts help you to program and automate few stuff on iPhone) so I also created /set and /get APIs, to store and get the text back. I named this web server I created as Telltail.

Screenshot of home page

Each program you create in Shortcuts app is called a shortcut. Using APIs I built, I created two shortcuts — one to receive the text stored in Telltail into the phone and another to send the text out of the phone. Beside giving the ability to invoke these shortcuts from within the Shortcuts app, it also gives an option to place an icon on the home screen and also on the share sheet, which I did.

Screenshot of shortcuts

On the website side, I placed a handy copy button but I soon found out that browsers don’t allow access to clipboard if your website is not on HTTPS. Thankfully, tailscale cert helped me to easily generate certificates for my server.

This is of what I posted a demo on Twitter that got some interest.

Then I started thinking…

Let’s See How Much I Can Stretch It

“It will going to stop somewhere. I just learnt about VPC, and this telltail has substance to work upon rather than going over gobyexample.com for the third time. And it will be a good excuse for learning about clipboard, as I always wondered how something I copy from VS Code appears highlighted in MS Word”, I told myself and got started working again.

iOS Shortcuts

I started with improving the shortcuts I made for iOS. Tailscale too provides few building blocks that I can include in my shortcuts. I heard about battery drain due to Tailscale on both GitHub and Reddit. To conserve battery, I experimented with few ways and ended up connecting to tailnet at the start of shortcuts and automatically disconnecting from tailnet at 6 AM and 6 PM.

Using share button works well for most of the time. But if you’ve selected a piece of text, to share it you need to go to the end of the tooltip to find the Share option, and sometimes that option isn’t even there. To solve this, I created another shortcut that can send the text I just copied.

I thought about how I can invoke it easily… Well, do you know, you can invoke a Shortcut by tapping twice or thrice your iPhone on its back? Or you can make sound of a crying baby to invoke it? Or you can use a floating button that is omnipresent on your screen and invoke a Shortcut from there? All of them come with either inconvenience or distraction though:

You can also mix and match them. I still think going to the homescreen and tapping the Shortcut is the most reliable and least distracting way to receive the text. And I settled on Back Tap to send off the text I copy.

Telltail Sync

I first tried to make the copy/paste from Telltail slightly convenient for myself by binding my Win + C and Win + V to invoke /set and /get APIs. In practice, doing that key combo is odd — you first do Ctrl + C to copy and then Win + C to send. Meanwhile, my mind started brewing the idea of making copy/paste seamless as it happens using Universal Clipboard on macOS, you don’t have to remember these extra actions to perform.

To make it happen, it requires:

To automatically get the contents from Telltail to my clipboard so I can perform paste, I used SSE (server-sent events) to listen any changes made over Telltail.

For automatically sending the content I copied, I explored and found utilities for my Linux machine that can look for any changes made in the clipboard and tell me when that happens. None of the option covered everything:

I was using Fedora with Gnome on Wayland, but facing issues to incorporate this feature, I switched to X.Org. And hence I went with clipnotify.

With all of this in place I built a way to keep my clipboard in sync; I named the program telltail-sync. And because the idea of clipnotify is simple — a CLI tool when invoked keeps itself running until something is copied — and because of the curiosity and interest I had, I implemented clipnotify for Windows and macOS so that Telltail Sync can work on those platforms as well.

To run both Telltail and Telltail Sync automatically when my system starts, I utilised systemd on Fedora and AutoHotKey on Windows as I found they work the way as I desire. I also switched to using tsnet for Telltail because it can self-manage SSL certificates for HTTPS and also because I was looking for a way to run Telltail in both Fedora and Windows. I needed it because I have dual-booted laptop with those OSes and I wanted to keep the same domain for Telltail irrespective of the OS it is being run on. (Update: It didn’t work out because an ephemeral node isn’t removed immediately, and even if that could happen, tsnet asks to pass a context which I have no idea where to get from.)

So, here is the result of all of this work:

This was my foray into VPN, Golang, systemd, cross platform programs and clipboard, and I learnt a lot in this.