42 Astoundingly Useful Scripts and Automations for the Macintosh

Sample scripts

You can download sample scripts from the book individually here.

Jerry Stratton

Edit (Bash)—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:

  1. Open the Terminal app (in your Utilities folder, which is in your Applications folder).
  2. Type the following (not including any list markers), pressing return at the end of each line:

    1. mkdir -p ~/bin
    2. touch ~/bin/edit
    3. chmod u+x ~/bin/edit
    4. open -t ~/bin/edit
  3. 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/bash
  • # edit a script file, ensuring that it exists and is recognized as a script file
  • # Jerry Stratton http://astoundingscripts.com/s/edit
  • 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.

Older posts