I've written before about how it's good to automate things on your computer when you can, especially when doing so will save you time in the long run.
Case in point.
I use an app called Numi on my Mac. This is basically a calculator that allows you to write notes in with the numbers. So you can type in a word problem, more or less. Then it is smart enough to just extract the numbers and give you an automatic result as you type, following any text instructions you add. For example it knows 4 times 5 is 20, understanding that "times" means *. That is a simple example; it can understand much more complex things than that.
This is useful for any number of reasons. It can be useful if I am trying to figure something out and walking myself through the problem, as most of us might have done in calculus or physics homework back in school. It can also be useful if I just copy a chunk of text and don't want to take the time to clean it up but want results.
A week or so ago the LGN pay bot broke. That's kind of par the course for Hive and not cause for alarm. Unfortunately things break when we have node issues around here. Bala quickly fixed the script and it was up and running again within a few days. When it started working again, it paid out payments for every missed day.
Well, I wanted to confirm that it paid out what was owed me. So I copied this chunk of text and pasted it into Numi
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Received from lgndivs0.315 HIVE
Now there are many ways I could extract just the numbers. A short perl script might be the easiest. But regular expressions can throw edge cases at you when you least expect it, so pasting it into Numi and letting that app do its magic is by far the easiest way.
And it did.
You see at the bottom of the screen we have "Total: 3.78 HIVE"
When I click on that total, it copies to the clipboard to be pasted somewhere. But here is where we run into a problem. What goes into the clipboard is Total: 3.78 HIVE, but I only want the number for pasting into my spreadsheet. If I paste what Numi gave me into my spreadsheet I will then have to double click on the cell, and edit it, erasing "Total:", "HIVE", and the white space. Doing this once is ok, but after doing this a lot, it can become annoying. And I do use this workflow a lot. Time to save a few seconds that will add up every time I do it!
I opened Keyboard Maestro. This is an amazing app that makes scripting the Mac a breeze. It doesn't do anything that I can't already do in Python or in AppleScript, but it makes the entire process faster and easier.
I created a Macro called "Clean Clipboard of Numi" and I set this macro to run every 1 second when Numi is active. Active means it is on the screen and has the focus. You might think that would waste a lot of processing power, but it's trivial. I'm only going to have Numi open a few minutes anyway, and of that it will only have the focus for a fraction of that time.
I then have an If statement saying if the clipboard matches "Total:" and a number, possibly followed by more text, then it should copy the clipboard to a variable, it should strip the number out of that variable, then it should copy the number back to the clipboard.
Boom. Now whereas before when I clicked on the result I got this in the clipboard
Total: 3.78 HIVE
Now after writing this macro, I get this
3.78
Here is the entire macro if you are curious. It took me about 10 minutes to write that, most of which was making sure I had the regular expression correct. I could do the entire thing in fewer steps, manipulating the clipboard directly instead of copying to a variable, but sometime I like doing it the long way just so future me can instantly grok what's going on when I come back and look at this long after it has faded from my memory.
So there we go. A few minutes of work that will save me time in the future every time I do this workflow from numi to a spreadsheet, not to mention the frustration of pasting into the spreadsheet only to realize I have to manually click in and erase all the text that pasted in along with the number.
Moral of the story: whenever you can, use automation on your computer to help yourself out. Also, if you run a Mac, buy Keyboard Maestro.
❦
David is an American teacher and translator lost in Japan, trying to capture the beauty of this country one photo at a time and searching for the perfect haiku. He blogs here and at laspina.org. Write him on Twitter or Mastodon. |