Extracting ID3 tags from the command line - two methods

As part of a Hazel rule to process downloaded mp3 files, I worked out a couple different methods for extracting the ID3 title tag. Not rocket science, but it took a little time to sort out. Both rely on non-standard third-party tools, both for parsing the text and for extracting the ID3 tags.

Extracting ID3 title with ffprobe

ffprobe is part of the ffmpeg suite of tools which on macOS can be installed with Homebrew. If you don’t have the latter, go install it now; because it opens up so many tools for your use. In this case, it makes ffmpeg available via brew install ffmpeg.

With that in place, extracting the title is just:

title=$(ffprobe -loglevel error -show_entries format_tags=title -of 
   default=noprint_wrappers=1:nokey=1 $file)

Extracting ID3 title with id3info

id3info is part of the id3tool suite of tools installed using - you guessed it - Homebrew. This solution also uses sd (brew install sd.) The latter is a more intuitive search and displace tool than the old stand-by sed.

IFS=$'\r\n'
tit2=""
for ln in $( id3info $file ); do
    if echo $ln | grep -q "TIT2"
    then
        tit2=$( echo $ln | sd '.*TIT2.*: (.*).*' '$1' );
        break;
    fi
done

Or a one-liner using perl:

echo $( id3info $file ) | perl -ne 'print $1 if /TIT2.*?\:\s+(.*?)\s===/;'

References

  • sd - intuitive search and displace - a sed replacement
  • ffmpeg - play, record, convert, and stream audio and video
  • id3tool - ID3 editing tool
  • Bash for loop - a short tutorial on the Bash for loop - something that I wasn’t really proficient at. Always good to revist.

Using variables in Keyboard Maestro scripts

Having fallen in love with Keyboard Maestro for its flexibility in macOS automation, I began experimenting with scripting in various languages, like my old favourite Perl. That’s when the fun began. How do we access KM variables inside a Perl script.

Let’s see what the documentation says:

So the documentation clearly states that this script

#!/usr/bin/perl

print scalar reverse $KMVAR_MyVar;

should work if I have a KM variable named MyVar. But, you guessed it - it does not.

After digging around in the Keyboard Masestro forums, I found an obscure post that pointed the way. It turns out that the Perl access to KM variables is completely different from what the documentation claims, the format is not $KMVAR_MyVar, it is actually:

$ENV{KMVAR_MyVar}

so the above script works if the variable is accessed from Perl that way:

#!/usr/bin/perl

print scalar reverse $ENV{KMVAR_MyVar};

Hugo cache busting

Justification

Although caching can make page loads notably faster, it comes with a cost. Browsers aren’t always capable of taking note when a cached resource has changed. I’ve noticed recently that Safari utterly refuses to reload .css files even after emptying the browser cache and clearing the web history.

Background

With a lot of help from the a pair of articles written by Ukiah Smith, I’ve developed a workflow for dealing with this problem during the deployment process. He describes two approaches to the problem of static asset caching, one an improvement on the other. I’ve implemented something like what he describes using the git file hash to modify the filename of the css files. When the client browser sees a new filename, it always reloads the resource. So the problem is to figure out how to only change the filename when the contents have changed. Let’s say you tweak a css parameter and want to ensure that client browsers load the correct version. We can use the git file hash, and append it on the filename. Then the only remaining problem is to make sure that the page head template knows how to find the correct version to bake into the pages. Here, our approach is the same as Smith’s.

iOS shortcut to clear Safari

Ios

(N.B. The next installment in my obsessional interest in thwarting surveillance capitalism. Read Shoshana Zuboff’s seminal work on the subject and you’ll see.)

Justification

Last week I outlined my evolving comprehensive approach to thwarting surveillance capitalism - that is the extraction, repurposing and selling of online behavioural surplus for the purposes of altering future behaviour.

This is a simple iOS shortcut to the embedded Safari setting for clearing Safari history and website data. It turns out that when iOS Safari is presented with a URL in a certain format, it will execute preference settings on the device. After a little trial and error, I noted that the setting Settings → Safari → Clear History and Website Data has its own URL: prefs:root=SAFARI&path=prefs:root=SAFARI&path=CLEAR_HISTORY_AND_DATA. By loading that URL through an iOS Shortcut, you can quickly sanitize iOS Safari.

My macOS and iOS security setup - Update 2020

(N.B. I am not a security expert. I’ve implemented a handful of reasonable measures to prevent cross-site tracking and limit data collection about my preferences and actions online.)

Surveillance capitalism is a real and destructive force in contemporary economics, politics and culture. Whatever utopian visions that Silicon Valley may have had about the transformative power of ubiquitous network technologies have been overwhelmed by the pernicious and opaque forces that profit from amplifying divisions between people. While I can’t change the system, I can change my own practices and reduce the degree to which surveillance capitalists, state actors and others who have no rights to my data.

Solzhenitsyn on the folly of looking for good/evil dichotomies

Постепенно открылось мне, что линия, разделяющая добро и зло, проходит не между государствами, не между классами, не между партиями, — она проходит через каждое человеческое сердце — и черезо все человеческие сердца. Линия эта подвижна, она колеблется в нас с годами. Даже в сердце, объятом злом, она удерживает маленький плацдарм добра. Даже в наидобрейшем сердце — неискоренённый уголок зла.

Alexander Solzhenitsyn
  <cite>Gulag Archipelago</cite>

My rough translation to English:

“Gradually it was revealed to me that the line separating good from evil passes not between States, nor between classes or parties. It passes through every human heart. The line shifts; it oscillates in us with the years. Even in a heart overwhelmed by evil, it retains a small bridgehead of good. Even the kindest hearts, there is an corner of evil not uprooted.”

On not minding what happens

Over-involvement in the future must be our most maladaptive trait.

Back in the 1970’s in Ojai, when Jiddu Krishnamurti drew enormous crowds to his extemporaneous talks, he touched on the liberation that comes from releasing the pointless hold on the future.1

Do you want to know what my secret is? You see, I don’t mind what happens.

Jiddu Krishnamurti
  <cite>Lecture, Ojai,California, USA; late 1970&#39;s</cite>

That’s it. Of all the teachings from the broad wisdom traditions, his one secret was not minding what happens. Notice that Krishnamurti didn’t say “I don’t care what happens.” It’s an important distinction. I can care about my own wellbeing and that of others in some future. But it’s pointless to hold onto that future in its imaginary state. As Oliver Burkeman put it:

We're all imposters

Reading Oliver Burkeman’s last advice column in decade-long series in The Guardian, I was struck by his advice on the imposter syndrome:

The solution to imposter syndrome is to see that you are one…Humanity is divided into two: on the one hand, those who are improvising their way through life, patching solutions together and putting out fires as they go, but deluding themselves otherwise; and on the other, those doing exactly the same, except that they know it. It’s infinitely better to be the latter (although too much “assertiveness training” consists of techniques for turning yourself into the former).

The Buddha was a list-maker

Beginning with “The Four Noble Truths”1, “The Noble Eightfold Path”2, and so on, the Buddha was a list-maker. I recently found a wonderful book, now out of print but freely available as a pdf. By David Snyder, Ph.D., it is called “The Complete Book of Buddha’s Lists - Explained”

Snyder does a brilliant job of reinterpreting these lists and framing them in the context of what the social sciences say about how we function individually and in groups.