Issue
Hello,
In my AppleScript I am running the following code,
do shell script "sudo networksetup -setproxybypassdomains Ethernet *.local, 169.254/16"
do shell script "sudo networksetup -setwebproxy Ethernet 127.0.0.1 8888"
do shell script "sudo networksetup -setsecurewebproxy Ethernet 127.0.0.1 8888"
However, it asks to enter password every time. I mean when the script is opened it asks for password 3 times for each line of process. In order to prevent from asking password I have to type the following in the Terminal,
sudo chmod u+s /usr/sbin/networksetup
When the Enter key is pressed it asks for the password and once entered and run the AppleScript then it doesn't ask for password (3 times) anymore.
But the user has to go to Terminal and type the above command. In order to prevent this I used the following code in the AppleScript,
do shell script "sudo chmod u+s /usr/sbin/networksetup"
So the user runs the AppleScript and it will auto set. But I get the following error message,
How to change the AppleScript for,
do shell script "sudo chmod u+s /usr/sbin/networksetup"
...to make it ask for password once and then execute the rest of the "...do shell script..." parts without asking for passwords. Or add the password along with the above line of code to make it work?
Solution
Have you looked at the definition for the "do shell script" command? You don't use sudo with that command. You would use "with administrator privileges" and you can supply a "user name" and "password" if you wish.
Do this... open AppleScript Editor. Under the File menu choose "open dictionary". Select StandardAdditions.osax from the dialog window. In the search field of the dictionary search for "do shell script" to see everything that you can do with that command.
For example, here's how you could use it. Good luck.
do shell script "networksetup -setproxybypassdomains Ethernet *.local, 169.254/16" with administrator privileges
Answered By - regulus6633 Answer Checked By - Katrina (WPSolving Volunteer)