Open shell script from Finder interactively

bashfinderterminal

I am running my manual backups with a shell script that asks me for a password. However, when I open the script from the Finder, it terminates immediately.

How can I get a script to run interactively when double clicking on it in Finder?

Best Answer

For a bash script to work from finder, it has to have the .command extension

For example, I created the following script to use sudo to ask for a password and then to output a welcome message, then "wait" to simulate execution time:

#!/bin/bash
sudo echo "Welcome to Ask Different"
sleep 10
exit 0

I saved it as test.command. You also have to make it executable: chmod +x test.command

Here's the result of clicking on the script:

enter image description here