How to create a universal (script) file for a Mac, based on several Terminal commands I have several Terminal commands I use for troubleshooting purposes, by typing them in one by one into the terminal window.

These commands require the user's password to be entered.

I'm looking for a way to create a universal (script) file with these commands. I want to be able to run the file on a Mac just by double-clicking on it or dragging the file over the Terminal icon.

I have never done anything like this before. Is there any way to create such a script? Please advise.
Short answer

A .command script should do the trick



Step-by-step


Open TextEdit and create a new file
Convert it to plain text by clicking Format > Make Plain Text
Add your commands, one per line.
For example, you could do:
#! /bin/bash
cd ~/Desktop
mkdir myCoolFolder
cd myCoolFolder
Run chmod u+x ~/Desktop/myCommandScript.command in your terminal, where ~/Desktop/myCommandScript.command is the path to your script. This will give the terminal permission to run the file.
You're done!  Double-click the file to run. Dragging over the terminal icon will also work. 


Notes:


If you need to do something that requires root (admin) access, you can prefix your command with sudo. When the script runs, you'll have to enter your password (and be an administrator)
If the end user isn't an administrator, but you need to do something that required root access, you can use su someAdminName, which will perform the command as someAdminName (you'll need his password).


You can also see here on Stack Overflow for a bit more information.