MacOS – Execute a BASH script… by double-clicking on it

high sierramacmacbook promacosterminal

Is it possible to execute a bash script by double-clicking on it? The shell script executes with $ ./script.sh without issues. Double-clicking the script opens TextEdit. It would be nice to execute by clicking on it…

$ system_profiler SPSoftwareDataType 
Software:

System Software Overview:

  System Version: macOS 10.13.4 (17E199)
  Kernel Version: Darwin 17.5.0
  Boot Volume: lily
  Boot Mode: Normal
  Computer Name: lily’s MacBook Air
  User Name: System Administrator (root)
  Secure Virtual Memory: Enabled

Best Answer

Maybe change the extension name to .command, but I think there should be some workaround to make .sh work.

To run by double click on the icon: open terminal and cd to directory of script. then chmod +x . finder will decide if it is excutable or not.