 |
 |
Applescript and sudo
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
Weird question. I have an Applescript that needs to execute a few shell commands as root. Now I can think of a few ways to do this. The easiest, of course, is simply to add yourself to sudoers so that you don't need to enter a password.
I was, however, curious of more general solutions.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
The do shell script event has the option to execute as root:
do shell script "<script goes here>" withadministrator privileges
It'll ask the user for their password before it executes.
According to the AppleScript dictionary, there should also be a 'with password <string>' option, but I can't seem to get that to work for some reason.
|
|
Gods don't kill people - people with Gods kill people.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
Yes that does it, but it asks for permissions for every call to do shell script. Here's the problem. The command is inside a repeat. It's basically a small script to change the permissions of a bunch of files.
Code:
on open itemList
set quot to ASCII character 34
repeat with thisItem in itemList
do shell script ("sudo chmod auo+rw " & quot & POSIX path of thisItem & quot)
do shell script ("sudo chown clarkgoble " & quot & POSIX path of thisItem & quot)
end repeat
end open
As I said, I simply modified sudoers and it runs great. I just was curious if there was a way to ask for administrator priviledges only once for the script.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
Originally posted by clarkgoble:
[snip]As I said, I simply modified sudoers and it runs great. I just was curious if there was a way to ask for administrator priviledges only once for the script.
Using the with password syntax seems to work for me, so you could:
Code:
set thePW to text returned of (display dialog "Enter your administrator password:" default answer "")
try
do shell script "chmod a+w..." password thePW with administrator privileges
do shell script "chown..." password thePW with administrator privileges
on error
display dialog "Oops. Wrong password?"
end try
|
|
Gods don't kill people - people with Gods kill people.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
That's a good idea except that it displays your password as you type it. Does Applescript have a password dialog box the way Javascript does?
As I said, it isn't that big a deal. The sudoers solution seemed best. It was interesting to come up against these limitations however.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |