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 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
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
Your terminal will look like this when you're done
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:
Right click on the "speak.bash" file to open the file menu and select "Get Info"
It will look something like this.
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:
Switch the "Enable" menu from "Recommended Applications" to "All Applications"
Select "Utilities", then "Terminal.app", then click the "Add" button
Click the "Change All..." button.
A dialog box pops up asking you to confirm the change. Click "Continue" to finalize the change.
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 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.
"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.