Running shell scripts on a Mac desktop

Write the bash script and give it a .command extension. If you double-click it then a terminal window will be open and the script will be ran.

If the script requires sudo access and you don’t want to be prompted for the password, then move the script to a separate script.sh file (you can use any name), and make the .command script and make it call via sudo:

#!/bin/sh
sudo /Users/username/script.sh

Add a promptless script execution to the sudoers file doing:

sudo visudo

Add a line like this:

username ALL=(ALL) NOPASSWD: /Users/username/script.sh