- Check42 for verifying Astounding Scripts—Friday, September 18th, 2020
-
As I wrote in the intro to 42 Astoundingly Useful Scripts and Automations for the Macintosh, there are two ways to get a script from the book to your computer. You can copy and paste it from the ebook. Or, you can go the traditional route and type it. It was old-school books with the latter sensibility that inspired me to write 42 Astounding Scripts, but I recognized that there were serious issues with that model, mainly to do with catching typos.
The best old-school computer magazine I read back in the day was The Rainbow for the TRS-80 Color Computer. Content-wise, it was very much like 80-Micro, which was the second-best: filled with amazingly cool BASIC programs, tutorials, and hardware projects. But unlike every other computer magazine that included BASIC code, The Rainbow had a program called rcheck and later, rcheck+.
Typos were inevitable typing in even short programs; the rcheck programs were designed to tell you not only that you had a typo but where the typo was, within a defined block of BASIC lines.
The rcheck+ program was so useful I’ve rewritten it in Perl, partly for the old-school community but mainly for myself.
It’s much more difficult to write something like that for modern scripting languages. BASIC had line numbers, which meant there were no blank lines. BASIC didn’t have indentation, which meant there was no worry about tabs vs. spaces. It didn’t even have tab characters in the code, at least on the Color Computer. And because memory was so tight, there weren’t very many spaces, either. There wasn’t even upper and lower case for the most part.
Still, I very seriously considered including a program like rcheck in 42 Astounding Scripts. Ultimately, I decided that it was likely to cause more problems than it solved. But last week I had the epiphany that an rcheck-style script could provide a literal line-by-line checksum, in fact a series of checksums that separate indentation from code, and that I could provide a zip file of those checksums.
- Edit (Zsh)—Thursday, August 1st, 2019
-
One of the first scripts in the book is a script to edit scripts. But that elicits a bootstrapping problem. Without the edit script, you can’t use the edit script to edit the edit script!
This edit script ensures that the script you’re editing or creating exists and that it is recognized as a script file by the operating system. For more information about the script, read 42 Astoundingly Useful Scripts and Automations for the Macintosh•. Basically, however, here is how to create the script:
- Open the Terminal app (in your Utilities folder, which is in your Applications folder).
-
Type the following (not including any list markers), pressing return at the end of each line:
- mkdir -p ~/bin
- touch ~/bin/edit
- chmod u+x ~/bin/edit
- open -t ~/bin/edit
- At this point, you should be in TextEdit. Paste in the code below and save.
At that point, you should be able to type edit SCRIPTNAME in Terminal, and automatically do all of the above steps for future scripts.
- #!/bin/zsh
- #edit a script file
- mkdir -p $HOME/bin
- FILE=$HOME/bin/$1
- touch "$FILE"
- chmod u+x "$FILE"
- open -t "$FILE"
I’ll have more about copying and pasting from ebooks in a future post. Or, of course, you can type into TextEdit far more easily than typing on a 64 by 16 screen as we used to have to do with books like this.