42 Astoundingly Useful Scripts and Automations for the Macintosh

About Astounding Scripts

Because I can!

Jerry Stratton

Catalina: iTunes Library XML—Saturday, October 19th, 2019
Why is XML so difficult in Python?

Apparently I’m not the only one to wonder why XML parsing is so much more difficult in Python than in other scripting languages.

I apologize in advance, but I usually wait at least one iteration before upgrading my operating system. That means at least 10.15.1 and perhaps 10.15.2. I rely too much on my computer to be one of the post-release beta-testers.

The big change in Catalina so far, as far as 42 Astounding Scripts is concerned, is that the iTunes replacement in Catalina does not have a “Share iTunes Library XML with other applications” option. This is causing a lot of problems for DJs, who use iTunes/Music to manage their collections but use other applications for gigs. And if you use the itunesLists script from 42 Astounding Scripts you’ll find that your own iTunes Music Library.xml file will no longer update either.

You can get around this problem by manually exporting an XML file from the Music app.

  1. Open the Music app.
  2. Under the File menu, choose Library and then Export Library.
  3. Name the file “iTunes Music Library.xml” and store it in the iTunes folder in your Music folder. You should know where it goes because there will already be one there.
  4. Save the file.

You’ll need to do this every time your library changes and you care about those changes; Music will not automatically update the XML file like iTunes did.

As I wrote in the book, these are all scripts I use regularly. So I’ll be looking at updating the script to remove its reliance on an XML data file. This will likely involve rewriting the script in swift; some of its more esoteric functionality will probably disappear. The main thing I use the script for is copying music playlists from the Mac to an SDHC card, and that’s what the new script will likely focus on.

I have to confess that removing XML support from the Music app was a completely unexpected change to me. XML is an extraordinarily useful data format, very well suited for exchanging hierarchical data—such as artists->albums->tracks—between applications. I partially blame Python’s developers. Python’s XML library has always been difficult to use. That’s why the itunesLists script requires installing the lxml library. Without that library, XML is much more convoluted in Python.

How to be a programmer—Saturday, August 31st, 2019

“Programmers need life experience, an appreciation for design, and patience working with other humans. Computer Science degrees prepare you for the abstract, the ideal, in other words, things that never occur in real life.”

I’m going to have more to say about this from my own perspective later, but this UpJourney article on how to be a programmer has good advice, as well as a great quote. It’s useful information even if you don’t want to be a programmer full-time, but merely a weekend programmer.

A computer programmer is not defined by what ‘they know’ but by what they build. — Bryan Osima (How to Become a Computer Programmer, According to People Who Did It)

Not quite quotable, but still good advice, is Reinder de Vries’s bit on mistakes leading to insights. If you can remember to see mistakes as an opportunity to ask “why?” you are on the road to mastering life. “Why didn’t it work the way I expected it to?” is a good question for any mistake, not just mistakes in programming.

It turns programming into a worthwhile life skill, like any other art.

Astounding@Goodreads—Wednesday, August 14th, 2019

I find Goodreads very useful for keeping track of what I thought about the books I’ve read. In fact, one of the scripts that I cut from 42 Astoundingly Useful Scripts was one for searching my Goodreads backup. I download the backup once a week, and so have it available for off-line searching; this also allows for more specific searches that the Goodreads website doesn’t allow for.

Here’s an older version of that script.

I cut it because, while that is an older version, I had already covered it, and in addition it would have been the longest script in the book. Part of the point of these scripts is that they can be typed in without too much work (and in fact, it should be a lot easier to type them in accurately than it was to type in the BASIC programs from the BASIC books that inspired me).

That said, I may change my mind in a future sequel. Using Pythonista on the iPhone and iPad, that script is especially useful because I have access to my reviews quickly while on the road.

42 Astounding Scripts is live!—Friday, August 2nd, 2019
Astounding Scripts book cover

This is the ebook cover from Apple Books. It’s also available in print on Amazon and as an ebook on Smashwords.

Do you want to play music on your computer? Do you want to create ASCII art from your photographs? Play podcasts back faster, snapshot web pages, display upcoming birthdays on your Desktop? Do horribly ancient filenames drive you crazy? Would you like to replace their underscores with spaces and separate their mashed-together words to readable ones? Would you like to organize your favorite recipes?

There’s a script for all of that in 42 Astoundingly Useful Scripts and Automations for the Macintosh.

42 Astounding Scripts shows you how to take control of your Macintosh.

I’ve been reading a lot of books about computers from the late seventies and early eighties. I cut my programming teeth on books like Ken Tracton’s 57 Practical Programs & Games in BASIC and the various forms of 101 BASIC Computer Games*. Reading these books again, I began to feel, not nostalgic, but jealous. Jealous of the younger me who had these books to read. As far as I can tell they don’t exist now. I wanted to read a book that didn’t exist.

Sometimes if there’s a book you really want to read, you have to write it yourself. — Ann Patchett (New York Times, Writers On Writing, August 26, 2002)

So I went through the scripts I use on a weekly and even daily basis, as well as a few scripts I hadn’t written yet but wanted to, and put together the book I really wanted to read. This is a book I would want to buy if I hadn’t written it.

Some of the scripts are a few lines long; others are a few pages long. Every one of them is something I’ve found useful and fun.

Older posts