The more I automate, the more there is to automate

I just spent literally three hours fiddling around with various automations for obsidian and my other apps. I couldn’t even begin to tell you what I did. I think it began somehow with wanting to create custom hotkeys, so I downloaded AutoHotKey and learned that scripting language. Then I wanted to add gestures, because my laptop is a 2-in-1, and I want it to be a better tablet, especially when I use it to read comics, so I downloaded GestureSign and fiddled around with that for ages. Then I wanted to figure out a way to move the cursor to the top of the page when I do a certain thing in Obsidian (the software I use for taking notes), and that got me into whether I can use the command line to put in key commands, and I dunno, it’s a whole huge thing. It’s really, really, really fun.

What it reminds me of, honestly, is this old tabletop game, Shadowrun, which was a weird alternate future Seattle which had magic and high technology.1 And your technology could be just as idiosyncratic and personal as your magic, especially because your tech was often a cybernetic body augmentation. Similarly, customizing my computer, loading it up with programs and scripts and commands, also makes it really feel like an extension of myself. Typing on a computer, when you have lots of shortcuts and such, is a very kinetic experience, full of shifting windows and sudden pop-ups and rapidly-executing code.

Taken from XKCD obviously

The irony is that the more you automate, the more time you have to read books or write blog posts or work on productive things, and yet all of those activities are very linear, in a way that the process of automation is not. When you read a book, you just sit down and do the same thing over and over, running your eyeballs along thousands of words. But when you write a script to collect and automate your notes on every book you’ve ever read, you metaphorically capture and alter all of those books in the course of a few hours. And yet, once you’ve written that script, it’s done. You’ve masticated and gurgitated fifteen years of reading–thousands upon thousands of hours, turned into grist for a mere programming exercise–and the prospect of going back and doing more reading seems quite pale and shallow.

Even as we speak, I’m thinking, hmm, the process of collecting all the link references above, so I can populate this post with links, is pretty taxing. Maybe I can write a script to automate that, and so I did:

// A tool that lets you output keystrokes, this just puts two line returns before the LinkRefs
xdotool key "{enter}{enter}"

// The path of the file I'm assessing
$path = "{{file_path:absolute}}"

// Searches for and captures any part of the file that has text in brackets
$match = Select-String " (\[(?>[^]]*)])" $path -AllMatch

// Appends that bracketed text to the end of the file, with a colon thrown in for good measure
$i = 0
while ($match.Matches[$i].Value -ne $null)
{ $print = $match.Matches[$i].Value+": "
Add-Content $path $print
$i++
} $i = 0

/* And of course after this code has run, I still need to go trawling through the internet for the actual links to attach to these references. It's literally two-thirty in the morning. Of course, it also occurs to me that this explanation won't make sense unless people understand how markdown files represent links. Basically if you want to link to something, you can put it in [brackets][] and then at the bottom of the file you can write [bracket]: http://www.link-to-bracketed-think.com and it'll get rendered as a link! But my problem is I always forget what I bracketed, and then I have to hunt through the file and look for them, and I inevitably forget one, so this tool collects all the bracketed things and presents them to me at the end in a handy list */

I thought the above was where I was going to leave things, but then I thought, what about footnotes! And what if I run this script on a file that already HAS some linkrefs below. It’ll be an absolute mess! So I decided that I wanted each file to have a pretty output like below at the bottom:

<!-- Insert LinkRefs And Footnotes Here -->

[//]: <> (Footnotes Go Below)
[^1]: Footnote text goes here

[//]: <> (LinkRefs Go Below)

[Interesting Thing]: wwww.a-link.com
[Another Interesting Thing]: www.another-link.com

This of course entailed ANOTHER ENTIRE DAY of work. It is literally 10 PM, and I’ve spent at least six hours today on making this script work. Now it looks like this:

$footnote = "`n`n[//]: <> (Footnotes Go Below)`n"
$linkref = "`n`n[//]: <> (LinkRefs Go Below)`n"

# $path = "{{file_path:absolute}}"
$path = "C:\Obsidian\Main\5 System Stuff\5.6 Test Strings\Blog.md"
$string = Get-Content $path -raw
$pattern = "<!-- Insert LinkRefs And Footnotes Here -->"
if ($string.IndexOf($pattern) -gt 0) {$string = $string.Substring(0, $string.IndexOf($pattern))}
    else {}
$string = $string+$pattern

$match = Select-String "(\[(?>[^]]+)])" -InputObject $string -AllMatch

$i = 0
if ($null -ne $match) 
{
        while ($null -ne $match.Matches[$i].Value)
        {
            $value = $match.Matches[$i].Value
            if ($value.IndexOf("^") -eq 1) {$footnote = $footnote+"`n"+$value}
                else {$linkref = $linkref+"`n"+$value}
            $i++
        }
        
} 
$i = 0

$string = $string + $footnote + $linkref
Set-Content $path $string

Much longer! Probably not very elegant either! And of course it didn’t work, and it needed hours of debugging too. But it does the job (although ironically this post, because it has lots of extraneous brackets you wouldn’t find in a normal post, has a lot of junk output from the script.)

I feel extremely proud of myself, but obviously the efficiency gains here are minimal. I’ve spent at least ten hours on automating this task that involves the back-end of my blog-posting system. And it doesn’t even automate the most time-consuming part, which is actually finding the link and copy/pasting it. Assuming I’ve saved ten minutes per blog post, and that I post fifty times a year, I’ve only saved about 8 1/3 hours per year. But what are the odds I’ll still be using the script even in a year? Probably not that high, since I’ll likely be using a different scriping language or a different text editor by then.

And I’ve gained skills that will help me in automating other tasks, to improve efficiency there too. But where does it end? I could easily spend my life automating, and do less and less primary work — reading and writing.

But whatever, it’s just a hobby.


  1. Recently reincarnated as an excellent video game 

Comments (

2

)

  1. William

    You are probably already aware of this, since it’s huge news, but I have found ChatGPT to be really helpful, especially when dealing with a programming language that has finicky and hard-to-remember syntax, e.g. BASH scripts.

    I find it lets me focus on the fun part of programming, thinking about the basic pieces I need and how they should fit together to get the output I want, and does the annoying part for me, actually writing out all the little functions with all their quirks.

    1. Naomi Kanakia

      I was vaguely aware of this, but your comment inspired me to fire up the old chatgpt account and ask the ai how to solve some ongoing problems. Wow!!!!!! That AI really knows its stuff! Gave me an elegant powershell script to do everything!!!!!! Thanks! This will really help.

%d