How to run admin scripts in non-admin account?

Hi, I’m trying to run some scripts that require administrative access in a limited acount, but I’m running into some problems.

I’ve tried using something like:

do shell script "shutdown -r" password "my_password" with administrator privileges

But it doesn’t work. I get an error message saying that the User isn’t on the Sudo list.

Is there a way to specify the User in addition to the the password? Something like:

do shell script "shutdown -r" user "admin" password "my_password" with administrator privileges


From StandardAdditions’ dictionary:

Just change your second script to user name instead of user.

If you supply a password without a user name, it will use the current user.

Depending on how you’re doing this, you could also use this:

do shell script "shutdown -r" with administrator privileges

That will prompt for both user name and password.

Doh! User Name instead of User… I was so close! :slight_smile:

One other question… when running multiple shell scripts with admin privileges, “;” seems to break the script.

When I try something like:

do shell script "cd /System/Library/CoreServices; rm randomfile" password "my password" with administrator privileges

I get an error message saying “cd not found”. Should I simply break the script into two seperate shell scripts, or can they be seperated by “&” instead?

Thanks again…

I don’t have any problems here.

do shell script "cd /System/Library/CoreServices; ls -1" with administrator privileges

Okay, maybe I typed something else wrong… I’ll try again.

Okay, I think I found the problem… the machines I’m administrating are running 10.3.2, and “user name” doesn’t seem to work.

The script below works fine in Tiger, but doesn’t work in 10.3.2. How can I modify it to make it work in earlier versions of OS X? Upgrading these machines isn’t really a possibility.

do shell script "cd /System/Library/CoreServices; ls -l" user name "admin_name" password "admin_password" with administrator privileges

I think I figured it out. The following script seems to work… I just used “as” rather than “user name”.

do shell script "cd /System/Library/CoreServices; ls -l" as "admin_name" password "admin_password"

Unfortunately, now I seem to have another problem… under the managed account, curl doesn’t seem to work (even when using admin passwords with administrative privileges). But maybe I’ll start a new thread about that…