Running sudo commands in Automator


If you’re wondering how to run sudo (for privilege escalation) commands in Automator, this is one way to do it.

Launch up Automator (of course).

sudoautomator01
Find Run AppleScript in the library of actions.

sudoautomator02
Then, drag it over to the workflow area on the right. By default, Automator will put in some script structure for you to work with. Feel free to just delete that all completely.

sudoautomator03
In place of the predefined script, put in

do shell script “sudo whatevercommandyouwanttorun” with administrator privileges

if it’s one command you want to run.

If you would rather run a script, it’s a similar syntax of

do shell script “sudo /path/to/youractualscript.sh” with administrator privileges

sudoautomator04
You can save your workflow as an application.

sudoautomator05
When you double-click your .app file, it should then prompt you for an administrator username and password and then run your bash command or shell script in a sudo-like way.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.