In this post, we will see how we can create a MAC commands executable / batch file consisting of commands to run (an alternate to .bat file of windowsOS in MacOC)
If you have worked on windows command prompt, you might used .bat or batch file which will have all the commands that you want to run, and when you double click on the .bat file, commands will be executed one by one.
In MacOS you can create a new file with file extension / format as .command
and enter all the commands you want to run as you run manually on MAC terminal.
Steps
- Create a new file, Spotlight | TextEdit or any kind of text editor
- Enter the commands to run from executable file, for example we will execute below command
echo Running terminal commands from an executable file
cd Desktop
ls
- now save the file (Command + s) and name is as
Test.command
- Double click the file that you just saved to execute
Troubleshooting
Sometimes when you double click on the file, you might get some error while executing, so you can give access of “ownership” and set the “execute” on the file
Open the terminal and enter below command for the file to run,
chmod u+x /path/to/.command/file
Now double click on the .command file, you will see the out put on a terminal with out any error 🙂
Hope this helps!
Leave a Reply