• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: do shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: do shell script


  • Subject: Re: do shell script
  • From: Bill Briggs <email@hidden>
  • Date: Tue, 15 Feb 2005 20:57:43 -0400

Title: Re: do shell script
At 1:41 PM -0700 2/15/05, Michelle Steiner wrote:
On Feb 15, 2005, at 1:32 PM, Bill Briggs wrote:

At 12:45 PM -0700 2/15/05, Michelle Steiner wrote:
How do you include the admin password in do shell script?

For instance, this requires a password:

do shell script "sudo pmset -a ams 0"

 If you include sudo in the string handed to do shell script, and you also include ' with administrator privileges password "supersecret" ' you may find the process with hang your Script Editor. I doesn't do it all the time on my Mac, but if the shell script is one that spawns a child shell it always does.

Do you mean that including "sudo" in the shell script and adding "with administrator privileges is redundant, and that one or the other can be eliminated?

 Yes. Just drop the sudo.


Here is the script so far.

property pword : missing value
display dialog "Do you want Sudden Motion Sensor turned on or off?" buttons {"On", "Off", "Cancel"} default button "Cancel"
set button_reply to button returned of the result

if pword is missing value then
        set pword to text returned of (display dialog "Enter your password." default answer "")
end if

if button_reply is "Off" then
        do shell script "sudo pmset -a ams 0" password pword with administrator privileges
else if button_reply is "On" then
        do shell script "sudo pmset -a ams 1" password pword with administrator privileges
end if

Not having the right machine, I can't test the script, though.

 My PowerBook has no motion sensor in the power management settings, so I can't test it here either. Is that the newer ones?


I did find that if I used an incorrect password, it does not return an error.

 You can coax that error to come back to AppleScript if you do a bit of shell redirection. The shell has three "files" it uses, apart from the files you explicitly name in your file system. Standard Input is 0, Standard Output is 1, Standard Error is 2. You can redirect these, and in this case you want to redirect Std Error back to Standard Output so it'll be fed back to the Script Editor (which I assume at this point only gets fed Std Out when the script completes (or not)). If you use this command.

do shell script "pmset -a ams 0 2>&1"  password "wrongpword" with administrator privileges

 you should get the error message when you feed it a bogus password. I used a different parameter but fed it the wrong password and got the error back by doing this:

do shell script "pmset -c spindown 30 2>&1" password "wrongpword" with administrator privileges

Try that on your machine and you should get the error kicked back if you issue the shell an incorrect password.


 I do need to add code to let the user change the password once it is stored, or else require her to type it every time.

 I'd dump the password property and just get the dialog to prompt for the password each time. One of these days there will be an "as password" option for display dialog.

- web
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: do shell script
      • From: Michelle Steiner <email@hidden>
References: 
 >do shell script (From: Michelle Steiner <email@hidden>)
 >Re: do shell script (From: Bill Briggs <email@hidden>)
 >Re: do shell script (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: do shell script
  • Next by Date: Re: Re: xml file created from directory structure
  • Previous by thread: [OT] Re: do shell script
  • Next by thread: Re: do shell script
  • Index(es):
    • Date
    • Thread