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

The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at and repair. — Douglas Adams (Mostly Harmless)

A manual for superBASIC—Saturday, May 30th, 2020

Because I like printed manuals, I’ve written a short manual for superBASIC. It’s available in print on Amazon.com, currently, for $5.99. It makes a useful reference if you use superBASIC; I use it all the time. It’s also available as a free ebook on most of the usual sites.1

I’ve also made some changes to how code generation works. I have changed the format of the DATASET macro, or dynamic constant. I’ve renamed %DATASETS! to !DATASETS%. I did this because I can envision having string constants as well, and I wanted to use the same format I use for variables, that is, ending in a dollar sign. So now a variable always begins with a percent, and a constant always begins with an exclamation.

The only visible change to the generated code is that I’ve standardized how blank lines get added around blocks and remarks. This greatly improves the readability of the resulting old-school BASIC.

Also, remarks no longer break on forward slashes, as these are common in URLs, which are common in the top comments I put in any program I write.

Internally, I’ve completely rewritten block generation. It generates the same code as before, but it is much easier to manage and view block types. This means that SWITCH/CASE is now the same kind of block as LOOP and IF/ELSE. LOOPs and IF/ELSE can be embedded in CASEs. Even SWITCHes can be embedded in CASEs.

This should make it easier to add an ELSEIF to IF/ELSE when needed, and to add a SWITCH ON to generate ON x GOTO statements. I probably won’t be adding any sort of FOR/NEXT loop because this turns out to be unnecessary on the Color Computer. All of the FOR loops that I’ve been wanting to BREAK out of are in subroutines, and the BREAK would have returned immediately from the subroutine. It turns out that returning from a subroutine clears out the FOR stack.

I always felt weird about jumping out of a FOR loop, leaving the poor stack perpetually waiting for a NEXT that will never come. Now that I know how Microsoft’s BASIC implemented its stack, I feel a lot better about it.

Text to image filter for Smashwords conversions—Wednesday, May 13th, 2020

Smashwords has a lot going for it, but it also has a lot of weird rules for what can go into books they publish, especially what can go into books that go through their automated conversion process. You’ll definitely want to read the Smashwords Style Guide before running any manuscript through their system. Some of the requirements are very counterintuitive even if—in some cases especially if—you are already familiar with ePub and other ebook formats.

Smashwords is mainly geared toward books with only two kinds of text in them, chapter titles and paragraphs—basically, novels. It was pretty much impossible to get a book of code to convert reliably with their automated process, so I ended up using Nisus Writer Pro’s macros and a couple of command-line scripts to create a custom ePub file for 42 Astoundingly Useful Scripts and Automations for the Macintosh.

By creating the ePub by hand I was able to carefully massage the book’s content to allow easily copying the scripts from the book so that people don’t have to type code if they don’t want to.1 This also meant, however, that 42 Astounding Scripts is only available in ePub format on Smashwords.

When I decided to write a manual for superBASIC it seemed it ought to be simple enough to go through the automated process and so take advantage of the multiple formats. SuperBASIC is a tool that allows writing old-school code using modern structures, but it’s still BASIC.

I still ran into a couple of issues but was able to script them away using Nisus Writer Pro’s easy and powerful macro language. Most of it was pretty simple, as you can see in the AppleScript I used to invoke the macro code:

TRS-80 Color Computer—Saturday, May 9th, 2020
Hello, World color bars

The TRS-80 Color Computer is a fascinating old-school personal computer. It is based off of the Motorola 6809 chip, and was the second computer I owned.

Most of this is about Extended Color BASIC on the CoCo, which I didn’t use much back in the day except for typing in programs from Rainbow. Most of the work I did for myself, I did in Microware’s OS-9.

If you want to write BASIC programs for the CoCo but prefer more modern methods, consider superBASIC. It provides loops, longer variables, and more, to make your CoCo code easier to understand and modify.

If you want to type in old code from Rainbow, look at rcheck+. It implements Rainbow’s rcheck+ algorithm in Perl.

Both of these allow you to more easily create CoCo code on a modern computer.

Random colors in your ASCII art—Wednesday, April 29th, 2020

I recently wanted to put dollar signs inside a Texas shape for a blog post about local sales taxes. That, of course, is easy with the asciiArt script: just set up a single-character palette and use a solid two-color image of Texas. But I also wanted to highlight the potential patchwork of sales taxes that people will have to know just to sell things online or even to send things sold in-person to the customer’s home.

The obvious solution was to randomly color each character in the image. The asciiArt script in the book can handle colors, but not random colors. It can use the color of the main image or overlay the color of a different image. Adding a random color option wasn’t difficult, however, because the script already grabs the red, green, and blue components of the image in a central place.

Here’s how I added a random color option to the script. The first question is, how to request random colors? There’s already a request for an overlay image file. What I want now is to, instead, overlay random colors. So I’m going to use --overlay random. It will make no sense to use an overlay file and random colors at the same time. The colors have to come from somewhere, and if they come randomly the file won’t be seen, and if they come from a file the random colors won’t be seen. So combining those options into a single place makes sense.

That means changing the case for --overlay:

[toggle code]

  • case "--overlay", "-o":
    • overlayFile = popString(warning:"Overlaying requires an image to overlay.")
    • if overlayFile == "random" || files.fileExists(atPath: overlayFile) {
      • useColors = true
    • } else {
      • help(message:"File " + overlayFile + " does not exist.")
    • }
  • case "--palette", "-p":

The bold lines, lines three through seven, are the new lines. All it really changes is to add “random” as a valid value for --overlay. If the overlay string exists as a file or, if the string is the word “random”, that section of code does what it did before. Otherwise, it displays the script’s help text and quits the script.

Because overlayFile can now contain text that is not a file, the check for reading the overlay file has to be changed, too:

Older posts