How I Created a .bat-like Executable on macOS

0 Shares
0
0
0
0
0
0
0

I recently made the jump from Windows to Mac, and while the transition has been smooth overall, I found myself missing a few Windows features, especially the ability to create simple .bat (batch) files to run multiple commands.

Being curious, I started digging and found the macOS equivalent of .bat files—and guess what? It’s super simple to set up using a .sh (shell) script.

If you’re like me and want to automate multiple terminal commands on your Mac, here’s how I did it 👇

What I Wanted

In Windows, I used .bat files to:

  • Run 2–3 commands one after another
  • Automate repetitive tasks with a double click

I wanted the same experience on macOS—a file that could run a series of terminal commands from any folder.

Solution: Use a .sh File on Mac

macOS uses Unix shell scripting, and you can create executable shell scripts with a .sh extension.

Here’s how I did it:

Step-by-Step: Create an Executable Script on Mac

Open Terminal
(Search for it using Spotlight or go to Applications > Utilities)

Create a new file

nano myscript.sh

Add your command

!/bin/bash
echo "Running command 1"
command1
echo "Running command 2"
command2
echo "Running command 3"
command3

Replace command1, command2, and command3 with your actual terminal commands.

Make it executable

chmod +x myscript.sh

Test it

./myscript.sh

Run It from Anywhere

Move it to /usr/local/bin

sudo mv myscript.sh /usr/local/bin/myscript

Now, you can open any terminal window and just type:

myscript

That’s It!

Now you’ve got your own Mac version of a .bat file—clean, flexible, and powerful. Switching from Windows to Mac opened up some new possibilities, and this one was a cool discovery for me.

read more