Automator: elevate to super user?

cwa107


Retired Staff
Joined
Dec 20, 2006
Messages
27,042
Reaction score
812
Points
113
Location
Lake Mary, Florida
Your Mac's Specs
14" MacBook Pro M1 Pro, 16GB RAM, 1TB SSD
OK, after many failed Google searches and hours of looking at different Automator tutorials, I'm hoping someone out there has a definitive answer for this seemingly simple question:

Is it possible to prompt for admin credentials and promote to super user during an Automator workflow (for example, to make a modification to a system directory)?

I've also tried running a shell script during the workflow, but using sudo just makes the workflow fail.

Bear with me, I'm relatively new to Automator and scripting on the Mac in general. Thanks in advance.
 
Joined
Sep 30, 2007
Messages
9,962
Reaction score
1,235
Points
113
Location
The Republic of Neptune
Your Mac's Specs
2019 iMac 27"; 2020 M1 MacBook Air; macOS up-to-date... always.
The Automator action to elevate to superuser, for tasks such as copying a file to /System/Library/CoreServices in the example you gave me earlier, needs to be an AppleScript. Add a "Run AppleScript" action, then use the following script (modify as need be to your preferences):

do shell script "sudo cp ~/Desktop/Temp/DefaultDesktop.jpg /System/Library/CoreServices" password "YourAdminPassword" with administrator privileges

The only problem offhand here is that your password is visible to anyone able to open the Automator workflow. If you save the workflow as an Application (once it's tweaked to your liking), then that's a non-issue. Another option is to use the AppleScript Editor to save the above script as an application, then have the Automator workflow call on that app rather than running the script itself. Of course, that will then require you maintain two files to run this one workflow.

FYI... this tip was adapted from this source.
 
OP
cwa107

cwa107


Retired Staff
Joined
Dec 20, 2006
Messages
27,042
Reaction score
812
Points
113
Location
Lake Mary, Florida
Your Mac's Specs
14" MacBook Pro M1 Pro, 16GB RAM, 1TB SSD
Works like a champ, thanks lifeisabeach!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top