2
I made a script to automatically shut down my computer. The problem is that it always asks the password. How should this be changed?
do shell script "shutdown -h now" with administrator privileges and password
2
I made a script to automatically shut down my computer. The problem is that it always asks the password. How should this be changed?
do shell script "shutdown -h now" with administrator privileges and password
1
do shell script "shutdown -h now", in theory would....but that results in a "non-super user" warning message.
As far as I can tell, and it makes sense, you have to be super-user to reboot the system from the command line. Why does this make sense? because you don't want someone rebooting the computer from an ssh session, if they don't have Super-user / root access...
I'd be interested if anyone found a way to do this....
Scott is accurate...
Tell application "finder" to restart -- Restart system Tell application "finder" to shutdown -- Shutdown system
But that will prompt the user to save any unsaved files... So if your trying to bypass prompts, it won't work.
1
Although a security risk, one way to do this would be to change the owner of your script to root and then change the setuid bit.
create the apple script as you described and save it to your Desktop as shut_me_down
open a terminal, cd to your Desktop folder and run:
chmod -R u+s shut_me_down.app/
sudo chown -R root shut_me_down.app/
Now when you double-click on the shut_me_down icon on your desktop it should shutdown without any prompts.
If you're looking for a command line way to do this (rather than clicking on a desktop icon) then you could skip the setuid/chmod thing and instead edit your sudoers file using
sudo visudo
Add your userid as someone that can run sudo without a password and then try running your script using "sudo scriptname"
Here's a link which may help too: Making an executable run as root every time - MacOSX.com
That's not going to make it suid. If you were going to do this you need to make the real binary suid which will be whatever.app/Contents/MacOS/whatever – bahamat – 2010-12-30T23:40:50.650
The -R option of chmod should take care of that. – Dale Hille – 2010-12-31T15:03:13.967
1
Here you go:
do shell script "shutdown -h now" user name "me" password "mypassword" with administrator privileges
0
Would this not work?
tell application "Finder" to shut down
1Finder will quit, not shut the system down. – Josh K – 2010-11-17T01:55:39.797
1@Josh wrong. I tried it and it wanted to save unsaved changes in all applications, and quit python in Terminal. Restarting Finder doesn't do that. – Daniel Beck – 2010-11-17T06:27:42.370
@Daniel: I don't do Apple scripting, isn't "shut down" telling it to Quit? – Josh K – 2010-11-17T15:02:00.843
1Nope. If you wanted to tell an application to quit you'd do tell application "Finder" to quit
. Shut down does what it says on the tin, as do restart, sleep and so on. I believe telling the Finder to shut down is a hold over from Mac OS where the Finder "was" the operating system, rather than the clearer distinction between the kernel and userland programs that Mac OS X inherits from Unix. – Scott – 2010-11-17T15:32:37.980
On a related note, if you want to find out about AppleScript commands, open up /Applications/Utilities/AppleScript Editor
and go to Window -> Library which gives you access to documentation on commands that scriptable applications support. – Scott – 2010-11-17T15:45:32.903
Why wouldn't you just use System Prefs -> Energy Saver -> Schedule (button on lower right)? – ricbax – 2010-11-17T01:53:46.300
1Because I don't have a set time when I want to turn it off. – tony_sid – 2010-11-17T05:06:00.863
Do you want to force a shutdown, or are you happy with stopping it if you have unsaved changes interrupt? – Daniel Beck – 2010-11-17T12:10:52.307
I'm trying to force a shutdown, that's why I made the script. The only thing that is interrupting it is the password request. – tony_sid – 2010-11-18T20:48:08.027