42 Astoundingly Useful Scripts and Automations for the Macintosh

Astounding Scripts on Monterey

Monterey removes Python 2, which means that you’ll need to replace it if you’re still using any Python 2 scripts; there’s also a minor change with Layer Windows and GraphicConverter.

Jerry Stratton, October 5, 2022

macOS Monterey: Apple’s mountainous Monterey OS, 12.6.; Apple; macOS; OS X; macOS Monterey

I finally upgraded to Monterey last month. There is only one major change as far as scripting goes, and it’s expected. Python 2 is gone, but Python 3 replaces it. Most other scripting languages remain.

Installing Python

If you want Python 2, you’ll need to install it yourself. If you’ve been using Python 3 via homebrew you can continue doing so; just be aware that there is now a default python3 in /usr/bin.

For your older scripts that still use Python 2, the easiest choice is the installer from Python.org. It doesn’t need to be managed through homebrew, because it’s never going to be updated again. Follow the directions to double-click the Install Certificates command as well, but do so from an administrative account.

If you are using homebrew for other things, you may find it easier to install Python 2 using homebrew as well; otherwise, other homebrew installations may try to install it anyway as a dependency. While there technically shouldn’t be any dependencies on Python 2, I found that this isn’t true for some older software. I’m not, apparently, the only one who is still using Python 2 for some important legacy apps.

Both methods of re-installing Python 2 will install it in /usr/local/bin, so that all you need to do to get your legacy Python scripts running is to replace #!/usr/bin/python with #!/usr/local/bin/python. If you were using /usr/bin/env python it will probably work without any change at all. But be aware that crontab will not necessarily import your environment, and so will not be able to find Python via env.

For that reason, I’ve just changed all /usr/bin/python and /usr/bin/env python to /usr/local/bin/python whenever I get the message that it can’t find an executable.

The transition from Python 2 to Python 3 is not seamless. Any command-line script that uses print, which is just about all of them, will fail.

The Ventura version of 42 Astounding Scripts will continue to use Python, though it will be Python 3.

Python modules

If you’re re-installing Python 2, you may also have to reinstall any modules, such as lxml, holidays, and loremipsum. If you’re switching from Python 2 to Python 3, you’ll definitely have to re-install them: the modules for each major version of Python are stored in different places.

After I reinstalled Python 2, I also had to sort of reinstall the modules I needed as well. They were all still installed—the macOS installer didn’t throw them away—but the new install of Python 2 wasn’t finding them. The easiest way to fix this was to reinstall using pip.

You may also have to specify a version. I found that holidays, for example, will not install the latest version. But it will still install version 0.9.9:

  • sudo pip install holidays==0.9.9

If you installed Monterey as an upgrade, your old installs should still exist in /Library/Python/2.7/site-packages. It’s just that whatever let the system know they’re there is gone. Reinstalling is the easiest way to get that link back. You can look in that folder to see which version you had before the upgrade. That’s how I knew I had had holidays version 0.9.9 working before the install, and how I chose which version to downgrade to when I discovered that the latest version would not install using pip.

PHP

It looks like php has been removed from /usr/bin also. It’s easily installed back using homebrew.

  • brew install php

This will place it in /usr/local/bin, so that your paths will change from /usr/bin/php to /usr/local/bin/php. If you’re using PHP for command-line scripts, of course. While I do use it on rare occasions, there are no scripts in 42 Astounding Scripts that use it.

PHP is mainly for web scripting, not command-line scripting.

GraphicConverter and Layer Windows

There’s been a change to getting “every window” in GraphicConverter. It either now includes windows of id -1, that is, palettes, or it removes the ability to (pretend to) interact with them. This causes problems with the Layer Windows script in 42 Astounding Scripts.

Because the non-window windows are at the bottom of the list, the script still works. But it reports that GraphicConverter does not support layering windows because the non-window windows error out. You can fix this by adding whose id is not -1 to the line:

  • copy every window to windowList

It should now read:

  • copy (every window whose id is not -1) to windowList

Looking forward to Ventura

One of the greatest features added to the not-yet-released Ventura is the ability to schedule emails. This will make the schemail script for scheduling emails far less useful. Assuming that scheduling emails remains a feature in Ventura’s Mail app, I’ll be replacing schemail with something else, but I haven’t decided what yet.

  1. <- Big Sur update
  2. Padmath in Ventura ->