Run Terminal Commands From the Dock on Mac
In this article
You can quickly execute a new terminal command from the Dock on a Mac by adding a Terminal shortcut that runs a specific command, or by using a small utility that creates a dock icon for any command you choose. The simplest built-in method is to create an Automator application that runs a shell script and then drag that application into the Dock; clicking it will execute the command without opening a Terminal window. For a more flexible approach, you can use a third-party app like DockCommand or SwiftDock, which lets you assign a command to a dock icon and even shows the output in a pop-up window.
Why Run Commands From the Dock?
Most Mac users open Terminal, type a command, and press Return. That works fine for occasional use, but if you run the same command repeatedly—like starting a local server, syncing files, or launching a script—the extra steps add up. Putting the command in the Dock turns it into a one-click shortcut, saving you from typing the same thing over and over. It also helps if you want to trigger a command without switching to Terminal, or if you want to run a command that requires admin privileges (though you'll still need to enter your password).
Method 1: Automator Quick Action (Built-in)
Automator is a free app that comes with macOS. You can create a small application that runs a shell script and then add it to the Dock. Here's how:
- Open Automator (from Applications or Spotlight).
- Choose File > New and select Application as the document type.
- In the left panel, search for Run Shell Script and drag it into the workflow area.
- In the script text box, type the command you want to run. For example:
echo "Hello from Dock"oropen -a Safari. - Set the Shell to
/bin/bash(default) and Pass input toto stdin(or ignore input). - Save the application (e.g.,
MyCommand.app) to a convenient location like the Desktop. - Drag the saved application into the Dock (next to the Trash or wherever you like).
Now clicking the Dock icon will run the command. The Terminal window does not appear; the command runs in the background. If your command produces output, you won't see it unless you redirect it to a file or use a tool like osascript to display a dialog.
Method 2: Third-Party Utilities
For more control, several free and paid utilities let you assign a command to a Dock icon and optionally show the output in a floating window. Popular options include:
- DockCommand (free): Adds a menu bar icon; you can create a dock icon for any command and choose whether to show output in a Terminal window or a pop-up.
- SwiftDock (paid, ~$5): Lets you create dock icons that run commands, open files, or trigger AppleScripts, with customizable icons.
- Platypus (free): Turns a shell script into a native Mac app that can be placed in the Dock; it also supports creating a menu bar app.
These tools are useful if you need to run a command with arguments, set environment variables, or capture output. They typically require you to grant permission in System Settings > Privacy & Security > Accessibility or Automation.
How to Pass Arguments or Use Variables
Sometimes you want to run a command with a variable, like a file path or a date. In Automator, you can use the input variable to pass the selected files or text. For example, if you create an Automator Quick Action (not an Application) that receives files or folders, you can write a script that processes them. But for a simple Dock click, you can hardcode the command or use a placeholder that gets replaced at runtime.
For instance, to run a command that includes the current date, you could use:
echo "Today is $(date)"In a third-party utility, you might be able to set up a prompt for arguments. For example, DockCommand lets you define a command with a placeholder like {input} and then ask for input when you click the icon.
Common Problems and Fixes
If the command doesn't run or you get an error, check these:
- Permissions: The app may need Accessibility or Automation permission. Go to System Settings > Privacy & Security and enable the app under Accessibility (for controlling the computer) or Automation (for controlling other apps).
- Path issues: If the command uses a tool that isn't in the default PATH (like
breworpython3), you may need to specify the full path or add it to the script. For example, use/usr/local/bin/brewinstead of justbrew. - Output not visible: If you expect to see output, redirect it to a file or use
osascript -e 'display dialog "Done"'to show a notification. - App doesn't stay in Dock: Right-click the Dock icon, go to Options, and select Keep in Dock.
Security and Safety Considerations
Running commands from the Dock is convenient, but it also means a single click can execute something potentially destructive. Always double-check the command you put in the script. Avoid using sudo unless you really need it, and if you do, be aware that it will prompt for your password. Also, be cautious with commands that delete files or modify system settings. If you download a third-party utility, make sure it's from a reputable source and check the permissions it requests.
Alternatives to a Dock Icon
If you don't want to use the Dock, you have other options:
- Keyboard shortcut: Use a tool like BetterTouchTool or Alfred to assign a hotkey that runs a command.
- Menu bar icon: Use an app like SwiftDock or Platypus to create a menu bar item instead of a Dock icon.
- Terminal profile: Create a custom Terminal profile that runs a command on startup and assign it to a keyboard shortcut.
- LaunchAgent: For commands that run at login or on a schedule, use launchd.
Frequently Asked Questions
Can I run a command with admin privileges from the Dock?
Yes, but you'll be prompted for your password. In Automator, you can use do shell script "your command" with administrator privileges in an AppleScript action, or simply prefix the command with sudo in the shell script. The app will then ask for your password each time you click it.
How do I see the output of the command?
Automator's Run Shell Script doesn't show output by default. You can redirect the output to a file (e.g., echo "done" > ~/Desktop/output.txt) or use an AppleScript dialog. Third-party utilities like DockCommand can display output in a pop-up window.
Can I run a command with a file I drag onto the Dock icon?
Yes, if you create an Automator Application that receives files or folders, you can drag files onto the Dock icon and the script will process them. In the Run Shell Script action, set Pass input to as arguments and use $@ to refer to the files.
Will the command run in the background or open a Terminal window?
By default, Automator applications run the command in the background without opening a Terminal window. If you want to see the Terminal, you can use a third-party utility that opens a Terminal window, or you can use osascript -e 'tell app "Terminal" to do script "your command"' to force it to open in Terminal.
Is there a way to make the Dock icon show a custom image?
Yes, you can change the icon of any app by copying an image file and pasting it into the Get Info window of the app (select the icon in the top-left, then paste). For third-party utilities, they often have built-in icon customization options.