1

I have a certain program that doesn't work right unless I run it as sudo. I don't mind having to type in my password, but I'd like to get out of the whole process of opening command line and typing "sudo ./"+script name. If you create a script that runs as sudo and click it, it just fails due to permissions. Is there a way to do this more quickly?

3
  • I would caution you from disabling the sudo system wide, it is there to protect you. Try adding the password in your script.
    – Ruskes
    Oct 21 '14 at 16:13
  • I don't know how to add passwords to a script. My question isn't about disabling sudo system wide.
    – Joe
    Oct 21 '14 at 16:57
  • 1
    add this to your script (do shell script "whatever" user name "username" password "password" with administrator privileges) replacing the "" with your stuff.
    – Ruskes
    Oct 21 '14 at 17:05
1

Run sudo visudo (or EDITOR=nano sudo visudo) and add a line like this:

%admin ALL=NOPASSWD: /usr/bin/myscript

Then create a .command file that runs /usr/bin/myscript:

echo sudo myscript>~/Desktop/test.command
chmod +x ~/Desktop/test.command
echo $'#!/bin/sh\nls /var/root'|sudo tee /usr/bin/myscript;sudo chmod +x /usr/bin/myscript

Or if for example you want to run sudo purge without having to enter a password, add

 %admin ALL=NOPASSWD: /usr/sbin/purge

to sudoers.

1
  • 1
    Is there a way to make a script ask for sudo password (Prompt the password Dialog Box)?
    – Royi
    Apr 8 '19 at 17:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .