blog advertising is good for you


blog advertising is good for you
User login

Performing a Clean Restart or Shutdown from the Terminal

The Mac has two different ways of doing a shutdown or restart: the Mac way and the Unix way. That is to say that one can go to the Apple Menu and pick restart or shut down and the system will gently close out all the programs and nicely tell everything it’s about to restart and then go on with itself.

The other way is to issue reboot or halt from the command line and then the system does it the Unix way: kill everything rather quickly and then reboot.

This is not to say reboot or halt are harsh, they do everything needed to stop the system properly. What they do not do is give graphical applications a notice and a chance to cancel shutdown if they want to.

Sometimes that’s useful, but sometimes you’re in the odd situation of wanting a clean restart or shutdown but are in the system via SSH and don’t have the GUI up. Never fear, it’s quite possible. Just issue the following command as the same user that’s logged in to the computer:


osascript -e ‘tell application “System Events” to restart’

You can use the command “shut down” if you want to power off the machine cleanly.

Average rating
(0 votes)
About Adam Knight
Adam Knight's picture

Author Biography

Adam Knight is one of the founders of Mac Geekery and is a geek at heart. Programmer by day, hacker by night, his daily life revolves around the Macintosh platform, which he has been a user and programmer for since the early days of System 7 when his LCII replaced his Apple //c.

In-between tech jobs, he’s managed to learn the basics of any web hacker: PHP, MySQL, Perl, Apache, Linux, *BSD, and the intricacies of ./configure —prefix=~/bombshelter/. Today, codepoet is concentrating on blogging again, writing some software for the Mac by himself (including Notae) and for his company (such as Switchblade) and has a few other toys coming out soon.

Bug him over AIM or email [link fixed].

spkane's picture

Doesn’t this require that “Enable access for assistive devices” be checked in the Universal Access System Preferences Pane, since that enable the ability to GUI script with Applescript and gives you access to the “system events” application?

I haven’t tested this, but I would expect it to be so.

Sean

————————————————————————————————-
Sean P. Kane
————————————————————————————————-
Congress appropriates. Microsoft lobbies. Citizens steal.

JC's picture

this isn’t gui scripting, so it doesn’t require the Assistive option.

spkane's picture

Cool, that’s good to know. I didn’t think you could access any “System Events” via Applescript without the Assistive option turned on.

Thanks,
Sean

————————————————————————————————-
Sean P. Kane
————————————————————————————————-
Congress appropriates. Microsoft lobbies. Citizens steal.

what program do you enter that code in?

Post new comment
The content of this field is kept private and will not be shown publicly.
14 + 5 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.