Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Run Mac Scripts By Double - Clicking Them

The process listed on this page sets up a mac to run any file ending in [TODO: Code shorthand span ] 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 :

- Create a file

- Give permissions to the file so it can run

- Set the file to run in the Terminal when it's double - clicked

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

bash
cd ~/Desktop
bash
echo "say it worked" > speak.bash
bash
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 [TODO: Code shorthand span ] 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 [TODO: Code shorthand span ] file with the [TODO: Code shorthand span ] process listed above.

- "chmod" stands for Change Modes on a file

- The parts of "u+x" are : "u" to modify the user level permissions, "+" we want to add the new permission for the user, "x" is the execute permission. Execute in this sense means the ability to run the file.

- Other options besides "u" are "g" for group, and "o" for other which means everyone else. We want to add the ability to run the file but there's a security idea of "least privilege". We would choose to let a group or the other list (which means everyone else) run the file, but that's not a requirement so we stick with the individual "u" for user.