Applescript for running sudo commands in terminal

I’m a newbie when it comes to Applescript and was wondering if someone could help with a basic request. I need to write a small script to do the following:

  1. Launch terminal

  2. Run the ‘Sudo -s’ command

  3. Enter the administrator password (in plain text)

and then

  1. run some sudo commands like “sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add administrator”

I actually WANT the administrator password to be in the script in plain text even though I understand the security risks (I will literally be the only person to ever see the script). I’ve trawled forums all over but can’t seem to find what I am looking for and cannot get it working by patching together the various commands I have found. Thanks in advance for any help you can give!

Sean

What need for sudo ?

do shell script « your command » with administrator privileges

or if you really want to play with matches you may use :

do shell script « your command » password « your password »

is designed to do what you described.

Look in the Standard Additions’s dictionary for details.

KOENIG Yvan (VALLAURIS, France) jeudi 10 octobre 2013 20:33:20