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
Here you go:
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.
1) create the apple script as you described and save it to your Desktop as
2) open a terminal, cd to your Desktop folder and run:
3) 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
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:
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.