home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Run Mac Scripts By Double-Clicking Them

October 2023

The process listed on this page sets up a mac to run any file ending in .bash in a command line terminal shell when you double-click on it. Scripts run that way have the power of full applications and can mess with, steal data from, or take over your computer.

The ability can be handy, but it adds to your responsibility of ensuring you don't run anything harmful.

If you only have one or a small number of scripts you wish to run by double clicking you can follow this same process but skip the step of doing "Change All..." Scripts you set up explicitly will work by double-clicking. Everything else will remain however it was before.

The Overview

The process of setting files to run when double-clicked has three parts:

File Creation And Permissions

These first instructions use the Mac's Terminal app to type in commands. It's in the Utilities folder inside Applications in the Finder. Open it and you'll see something like this (but with your username and computer name instead of "alan" and "dojo" which are mine)

Copy and Paste these three lines into the terminal, pressing enter after each one

Code
cd ~/Desktop
Code
echo "say it worked" > speak.bash
Code
chmod u+x speak.bash

Your terminal will look like this when you're done

Run In The Terminal

Scripts need to be associated with the Terminal App in order to run. Otherwise, they'll most likely open in an editor of some type (or just not at all).

The steps for associating .bash files to run in the Terminal are:

Step 1

Right click on the "speak.bash" file to open the file menu and select "Get Info"

It will look something like this.

Step 2

Click on the "Open with:" menu, scroll to the bottom and choose "Other..."

(My "Open with:" started with "Visual Studio Code.app". Yours might well start with something else. That's fine. It won't effect these instructions.)

The window that opens will look something like:

Step 3

Switch the "Enable" menu from "Recommended Applications" to "All Applications"

Step 4

Select "Utilities", then "Terminal.app", then click the "Add" button

Step 5

Click the "Change All..." button.

Step 6

A dialog box pops up asking you to confirm the change. Click "Continue" to finalize the change.

Running The Script

Now that the file is set, double-click it. If everything goes to play, (and your volumes up) the computer will say "it worked". When it does a window opens that looks something like this:

That's It

That's all there is to the setup. You're now set to write and use scripts that you can fire off simply by double clicking them. It's a fun power to have.

The only other thing to know is that you'll need to set the permissions for each new .bash file with the chmod u+x FILENAME process listed above.

═══ § ═══