SHUTDOWN script format?

i want to write a script using the command to shutdown as done in terminal

"shutdown -r now"

(please correct me if i'm wrong)

ive been using script editor to attempt saving a script but i'm doing something wrong. i am using the terminal version because i don't want it ask to close tabs on browsers, etc. i want it to shutdown the computer without any questions. force quit, whatever it takes.

what is the best way to accomplish this? or what format does the script need to be saved in?

anyway i cant save it as .sh extension. it always adds the .rtf via finder. in terminal, it says the command "rename" can't be found.

i need to create something that is a clickable executable file that will initiate the shutdown command in terminal, or with something to the same effect.

Click to expand...

The command to rename a file is mv-- short for move.

Code:

mv filename.rtf filename.sh

But that's not your only problem. From the .rtf extension I'm guessing that you wrote the script in TextEdit. That's not going work. Files ending in .rtf are Rich Text Files. They include invisible characters that tell the document what font, how big, etc. All that stuff will get in the way of the script running correctly.

You need to create the script in a text editor that can save pure text files. TextWrangler is a decent choice. Or if you feel up to it, use built-in applications called pico, nano, or even vi or emacs directly in Terminal. (You'll have to find tutorials for those elsewhere)

Once you create the correct kind of text file, then you can set its execute bit and run it from Terminal.

tarl: thanx for the info! ive been looking for that one. i really just need to find a book with the commands for terminal. some of the old xenix ones work and some don't. i need to update my knowledge!

tarl: thanx for the info! ive been looking for that one. i really just need to find a book with the commands for terminal. some of the old xenix ones work and some don't. i need to update my knowledge!

i just figured that out. but what i couldn't figure, was how to add my account (the only one, and it is admin obviously) as a super user aka add me to the sudoers

Click to expand...

The first AppleScript example (with the tell) is much simpler because you don't have to deal with sudo, setting up sudoers, and stuff of that nature. Simple is good. Means less things to possibly goof up or break.

I initially thought you were trying to shutdown a Mac remotely. After rereading you posts it seems like that is not the case.

Shutting down the Mac with any of these scripts will work, but it's quite likely to lead to problems down the road. Shutting down a Mac by always force quitting applications and the OS is going to lead to corrupt files.

The first AppleScript example (with the tell) is much simpler because you don't have to deal with sudo, setting up sudoers, and stuff of that nature. Simple is good. Means less things to possibly goof up or break.

In fact, you can shorten the AppleScript to just one line:

Code:

tell application "Finder" to shut down

Click to expand...

I did that before, but it will want confirmation of any open apps. Safari closing tabs, or firefox, transmission with active transfers,iTunes wiu someone connected to shared library, etc

I initially thought you were trying to shutdown a Mac remotely. After rereading you posts it seems like that is not the case.

Shutting down the Mac with any of these scripts will work, but it's quite likely to lead to problems down the road. Shutting down a Mac by always force quitting applications and the OS is going to lead to corrupt files.

Why are you not using the Shutdown command in the Apple menu?

Click to expand...

I am doing it remotely. I'm using my iPhone safari which connects to a server on my mac (iPhone remote aka telekinesis) and allows me access to files like turning on a movie, or opening a picture, or even turning on an app. So if I want to shutdown the mac without all the "are you sure?" dialogs which I can't see all of them anyway because I have multiple screens, I need to shut it down with terminal. This won't be so often that I'm worried much about file corruption.

Does anyone know how to make my account a sudoer or some code I can put in with the shell script?

You need to use something else since the command will only reboot the machine instead of doing a power down. Use the "poweroff" command as lenchnikin says or check out man shutdown for more options (like -h).
You also need to configure every program to not ask to save anything when shutting down. This might also be accomplished via some sort of applescript.

You need to use something else since the command will only reboot the machine instead of doing a power down. Use the "poweroff" command as lenchnikin says or check out man shutdown for more options (like -h).
You also need to configure every program to not ask to save anything when shutting down. This might also be accomplished via some sort of applescript.

Click to expand...

Actually, I goofed because I'm used to '-r' by default -- force of habit.

thanx to all who replied. what i finally did to accomplish my desired result was to use my iphone to access terminal via mobile safari and then log in as root and use either the "shutdown -h now" since i have finally put a password on my single account, i plan on experimenting with "shutdown -r now" and see if it reboots to a login screen as it should.

thanx again! we have a great community here. i appreciate all the comments and input

To the user who mentioned the -s flag, that puts the machine to sleep (whatever state the power management file has defined for that).

Also, you can too get extension-less plain text files out of TextEdit. Select Format > Make Plain Text, then when you save it, don't type an extension, and uncheck the box that says "If no extension provided, use .txt". There's also an option in preferences to not append the .txt unless the user actually types it.

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.