The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Run Mac Scripts By Double-Clicking Them

TODO: Pull subtitle into page object

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:

- 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)

A just opened mac Terminal app window showing a single with with the user name alan and the machine name dojo on it

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.

Notes

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Run Mac Scripts By Double-Clicking Them

-- warning

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.

-- h2

The Overview

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

-- olist

- 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

-- h2

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)

-- image
-- double-click-script-empty-terminal

A just opened mac Terminal app window showing a single with with the user
name alan and the machine name dojo on it

-- p

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

-- code
-- bash
-- type: nonums

cd ~/Desktop


-- code
-- bash
-- type: nonums

echo "say it worked" > speak.bash


-- code
-- bash
-- type: nonums

chmod u+x speak.bash


-- p

Your terminal will look like this when you're done

-- image
-- double-click-script-showing-commands


-- h2

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:




-- h3

Step 1

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

-- image
-- double-click-script-right-click-menu

-- p 

It will look something like this.

-- image
-- double-click-script-get-info-window


-- h3

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.)

-- image
-- double-click-script-choose-other

-- p

The window that opens will look something like:

-- image
-- double-click-script-app-selection


-- h3

Step 3

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


-- image
-- double-click-script-all-apps


-- h3

Step 4

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

-- image
-- double-click-script-utilities-terminal

-- h3

Step 5

Click the "Change All..." button. 

-- image
-- double-click-script-change-all-button

-- h3

Step 6

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

-- image
-- double-click-script-change-all-confirm

-- h2

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:


-- image
-- double-click-script-final-terminal

-- h2

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. 

-- notes

- "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. 





-- categories
-- Command Line 
-- Mac 

-- groups

-- metadata
-- date: 2023-10-22 17:52:20
-- id: 2x8xazwc
-- site: aws
-- type: draft 
-- status: published