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
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
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.
Here you go:
do shell script "shutdown -h now" user name "me" password "mypassword" with administrator privileges
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
Would this not work?
tell application "Finder" to shut down
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.
/Applications/Utilities/AppleScript Editor
and go to Window -> Library which gives you access to documentation on commands that scriptable applications support.