42 Astounding Scripts

MacOS uses Perl, Python, AppleScript, and Automator and you can write scripts in all of these. Build a talking alarm. Roll dice. Preflight your social media comments. Play music and create ASCII art. Get your retro on and bring your Macintosh into the world of tomorrow with 42 Astoundingly Useful Scripts and Automations for the Macintosh!

Jerry Stratton

In large programs the only unlabeled constants are 0 and 1. — John M. Nevison (The Little Book of BASIC Style)

Another Safari 14 Services workaround—Saturday, January 2nd, 2021
Automator Copy to Clipboard example

At least in Catalina, using Copy to Clipboard as the final action does not block the output from replacing selected text. Which makes it a useful workaround for Safari 14, which does block selected text replacement.

As of December 15, 2020, Safari—currently 14.0.2 on my computer, running Catalina 10.15.7—still doesn’t work with Services where the “Output replaces selected text” option is checked. The Quick Action gets the selected text, but the selected text is erased. It’s replaced with nothing.

However, one workaround, at least for commonly-used Services, is to make the last action in the workflow “Copy to Clipboard”. This will allow you to immediately paste the results into the Safari text field.

This won’t harm the Quick Action’s behavior in other apps—the script’s output will still replace the selected text. It will, of course, replace whatever’s currently in the clipboard with the script’s output, so I wouldn’t recommend using this workaround except where necessary.

I’ve used this workaround on my moronify and markdown to blog HTML Quick Actions, which I use pretty much only in browser text fields.

I’d be interested to hear if Automator Quick Actions work on Big Sur. I’m still waiting on a few app updates before I switch, but I don’t have any major projects blocking a system upgrade. Once I have Big Sur on board, of course, I’ll let you know what changes need to be made to any of the 42 Astoundingly Useful Scripts and Automations.

Create Color Computer binaries from hex values—Wednesday, December 30th, 2020

The December 1987 issue of Rainbow has a very interesting program from John Mosley that purports to be “a four-voice music and graphics program” that works with the CoCo 1 and 2. It consists of a short BASIC program to create the graphics, and a shorter BASIC program to allow the reader to type in the hexadecimal values for the music, one value at a time.

Screw up one number, and you have to start over, this time not screwing up elsewhere. Or you have to understand POKEing enough to rePOKE just the numbers you screwed up, and know where they are—probably by writing a BASIC program to display values in memory and ask you if they’re correct, one by one.

It seemed more reasonable to type all of the hexadecimal numbers into a text file, and then use a script to create the BIN file; if there’s an error, fix only that error in the text file instead of retyping everything.

The format of BIN files turns out to be fairly simple. From Walter Zydhek’s Disk BASIC Unravelled II, there is a preamble and a postamble, both five bytes long. The preamble contains the length of the data and the address the data should be loaded to:

000Preamble flag
1-2XXXXLength of data block
3-4XXXXLoad address

The postamble contains the execution (EXEC) address:

0FFPostamble flag
1-20000Dummy value
3-4XXXXExecution address

The script accepts the following arguments:

load addressdecimal or hex address for location of binary data in CoCo RAM
exec addressdecimal or hex address for starting execution; defaults to load address
filenamesfile[s] to pull data from; data can also be piped
--basicthe text is a BASIC file; pull hex values from DATA lines
--columns <column count>verify that each line contains a specific column count
--helpprint this text
--quietdo not output bin data
--verboseprovide information about the binary program
Smashwords Post-Christmas Sale—Saturday, December 26th, 2020

From now through the rest of the year, you can get the Astounding Scripts e-book and the Dream of Poor Bazin ebook from Smashwords at 75% off as part of their end-of-year sale. Use discount code SEY75.

If, like me, your best memories of Christmas morning are building things with your new toys, then 42 Astounding Scripts will awaken your Spirit of Christmas Code. It’s filled with command-line programming toys for your Macintosh, from creating ASCII art using your own photographs, to creating great music or even playing your music files backward.

If, on the other hand, your best memories are of losing yourself in a grand, swashbuckling adventure, The Dream of Poor Bazin is just what the Dumas ordered. Join young, provincial journalist Stephen Price Blair as he learns the trade in Washington, DC and exposes conspiracy, hate, and murder in the land beyond the Potomac.

While the discount code (SEY75) is specifically for Smashwords, both of these books are also available in print, and, most likely, your favorite ebookstore wherever it is.

Sparkling lights for Christmas—Friday, December 25th, 2020
Christmas lights over bumpy surface

A bumpy surface, scaled by 10%.

It’s time once again to play with tinker toys for Christmas. This Christmas, like last Christmas, the tinker toys are the Persistence of Vision raytracer. (And by the way, if you enjoy this kind of toy, Astounding Scripts is currently on sale.)

And this time, instead of using the command-line version, I used the GUI version from Yvo Smellenbergh. I’m using the 3.8 development version although I’m not sure it matters for this scene; the 3.7 version is likely fine also. However, as betas go this has so far been very reliable. At the time of writing, I have not had a single crash, and the scenes render as I expect them to.

The GUI version recognizes the syntax of POV and highlights the keywords just as Textastic does for other scripting languages. It can also list your variables and macros, and it provides easy templates for the various POV shapes and scene elements.

I was inspired by the Christmas tree photo I used in O Little Town of Bethlehem, which is a photo of the Macy’s Christmas tree in San Francisco. I was also inspired by the wonderful artwork in the Charlie Brown Christmas Special. This video is a rough combination of those two inspirations.

You can easily change the background. The background in this scene is a shape like any other: a plane. I didn’t do anything special to create it, just played around with normals in Persistence of Vision. Normals are basically roughness on the surface of a shape. The most common is probably a bumpy surface, and that’s what I used first, scaled by .1. Scaling a bumpy surface by less than one makes the bumps smaller and more numerous.

[toggle code]

  • normal {
    • bumps
    • scale .1
  • }

After playing around while reading the manual about normals, I ended up choosing the marble keyword, with a turbulence of 1. That's pretty much all I did—read through the various keywords for altering the normal and chose the one that felt right.

You can download the scene file, as well as the music that went along with it, as a zip file (Zip file, 10.6 KB).

Older posts