KDE Klipper-like Clipboard Actions for Windows, Using Power Automate

I have an unusual use case in my Trilium setup; there’s the actual Trilium server endpoint, accessible only within my internal network but has 100% Trilium functionality. And then, as of today, there’s txt.otl-hga.net, which is basically a thin nginx config that checks to make sure you’re accessing an intentionally public URL before letting you through, effectively only allowing access to my explicitly shared notes.

Trilium, for the most part, supports this configuration just fine. At one point, they even ran their official website on a Trilium instance, so stuff like this is not unheard of within the Trilium community. The only gotcha is, when I share a note, the URL that appears within the Trilium UI points to the Wireguard endpoint, and most folks can’t get to my note from there.

I didn’t want to manually change the URL every time, so I started looking towards clipboard actions. In KDE, Klipper has this functionality built in. But until recently, I thought I was gonna have to write my own program to handle it in Windows, because the idea of an automatic clipboard actions program doesn’t seem to be one the Windows community has heard before.

I’m half right. I still have to do the actual logic programming myself, but I don’t have to bust out MSVC and Win32 API docs to do it. Are y’all familiar with the Android automation app, Tasker? It turns out Microsoft makes a Windows program that does the same things, called Power Automate.

Quick Primer For People New To This Kind of Automator

In Power Automate, the first thing you do is create a new “flow”. This brings you into the flow designer.

There is much going on here.

It looks like a lot, but it’s not so bad! It also looks like Scratch, that programming by flowchart tool made to teach kids programming, but this is aimed more at tech professionals trying to do some technical stuff without busting out VS Code and language documentation.

The actions panel also has a filter box at the top, which is good because there’s enough categories of actions, each containing anywhere from about six to sixty actions themselves, to make the full list of categories need a scrollbar even when they’re all collapsed. Power Automate can do a lot of things. Today we’re just doing some automated clipboard management.

How To Build Your Flow

First of all, Power Automate does not seem to have a way to automatically run a flow when the clipboard changes, at least not as far as I can find at the time of writing this article. So we’re gonna take a more generic approach; we’re gonna loop “forever” and just check if the text in our clipboard is something we need to manipulate. (Those with extensive programming experience, please forgive me, but I’m going to rehash some basic programming tricks just in case this ends up being the top Google result someday.)

To do this, first add a “Set Variable” action, name the variable “ShouldRun”, and set its default value to 1. Right after that, add a “loop condition”, and set it to “While ShouldRun == 1”. I suppose you could just use a regular infinite loop here, but I like putting exit conditions in my things.

Within this loop, your first action should be, understandably, “Get Clipboard Text”. Give it a variable name. I used ClipboardText. Then, add an If block. For my specific use case, I used “If ClipboardText starts with <wireguard URL for my trilium endpoint>”, but naturally, you can test the clipboard text however you need.

Within this If block, I personally added “Replace Text” (replace the wireguard url with https://txt.otl-hga.net, and save it to Replaced), and then used the “Set Clipboard Text” action to put the contents of the Replaced var into the clipboard. Then, for my own personal preference, I added a “Display Message” to let me know the flow did something.

There’s also an Else If (which I used to check if the clipboard info is HGA_CLIP_FLOW_OFF and then set ShouldRun to 0). And then, finally, at the end of the loop block, I added a “Wait 1 second”, just to prevent it from spinning the CPU endlessly.

Once it’s all set up, just save and run. It’s that easy. I can’t seem to figure out how to make it run on startup, but it does have hotkeys. I didn’t check to see if binding it to Ctrl+C would work as preferred.

  • June 15, 2023