The conversation on this page has been archived and is no longer active.

"Sleep" over network

Message #1 - Posted 2003/07/07 - Sandman

Is there a way to tell my Mac to go to sleep without having physical access to it? I am using wakeonlan to wake it, but I would like to put it to sleep when I'm done with it - is there a command I can use in SSH for example?

On a similar note - is there a command to put hard drives to sleep?

Sandman[.net]

Message #2 - Posted 2003/07/08 - Sander Tekelenburg

Previously, Sandman wrote:

Is there a way to tell my Mac to go to sleep without having physical access to it? I am using wakeonlan to wake it, but I would like to put it to sleep when I'm done with it - is there a command I can use in SSH for example?

I haven't tried this, but you can use AppleScript to tell the Finder to sleep. So if you'd create an applet like the one below, save it on the remote machine, and trigger it from your ssh session ("open [path to applet]"), I'd think that should work.

tell application "Finder"
delay 30
sleep
end

Possibly, with your ssh session still active, that might immediately wake the remote Mac again. Hence the delay in the script, to give you another 30 seconds (or whatever you prefer) to log out before the sleep command hits. But it may not be necessary.

It should also be possible to do this directly from the terminal. See "man osascript".

Message #3 - Posted 2003/07/08 - Noses

Sandman wrote:

Is there a way to tell my Mac to go to sleep without having physical access to it? I am using wakeonlan to wake it, but I would like to put it to sleep when I'm done with it - is there a command I can use in SSH for example?

On a similar note - is there a command to put hard drives to sleep?

You might take a look at pmset(1); it's not entirely what you want (you can't tell the machine to go to sleep but you can set the sleep timer to something quite low which will permit you to wake it up and reset that value without it falling asleep while you are doing it) but it will give you access to the disk spindown timer.

Noses.

Message #4 - Posted 2003/07/08 - Sandman

Previously, Sander Tekelenburg wrote:

Previously, Sandman wrote:

Is there a way to tell my Mac to go to sleep without having physical access to it? I am using wakeonlan to wake it, but I would like to put it to sleep when I'm done with it - is there a command I can use in SSH for example?

I haven't tried this, but you can use AppleScript to tell the Finder to sleep. So if you'd create an applet like the one below, save it on the remote machine, and trigger it from your ssh session ("open [path to applet]"), I'd think that should work.

tell application "Finder"
delay 30
sleep
end

Possibly, with your ssh session still active, that might immediately wake the remote Mac again. Hence the delay in the script, to give you another 30 seconds (or whatever you prefer) to log out before the sleep command hits. But it may not be necessary.

It should also be possible to do this directly from the terminal. See "man osascript".

Thanks! You got me on the right track. In a SSH session, I can write:

sudo osascript -e 'tell application "Finder" to sleep'

To put the system to sleep. I wish I could, from another system, do:

ssh hostname sudo osascript -e 'tell application "Finder" to sleep'

But that doesn't work.

Sandman[.net]

Message #5 - Posted 2003/07/08 - Sandman

Previously, Noses wrote:

Sandman wrote:

Is there a way to tell my Mac to go to sleep without having physical access to it? I am using wakeonlan to wake it, but I would like to put it to sleep when I'm done with it - is there a command I can use in SSH for example?

On a similar note - is there a command to put hard drives to sleep?

You might take a look at pmset(1); it's not entirely what you want (you can't tell the machine to go to sleep but you can set the sleep timer to something quite low which will permit you to wake it up and reset that value without it falling asleep while you are doing it) but it will give you access to the disk spindown timer.

Thank you. I soled the go-to-sleep thing with applescript, but I still would like to just spin down the drives... Ah well, not that important I suppose.

Sandman[.net]

Message #6 - Posted 2003/07/08 - Bev A. Kupf

On Tue, 08 Jul 2003 15:00:45 +0200,
Sandman (mr@sandman.net) wrote:

Thanks! You got me on the right track. In a SSH session, I can write:

sudo osascript -e 'tell application "Finder" to sleep'

To put the system to sleep. I wish I could, from another system, do:

ssh hostname sudo osascript -e 'tell application "Finder" to sleep'

The syntax of the command that you have been trying is not quite right. You can use ssh from a remote system to get your Mac to sleep. Here is one correct command syntax (there are others, but this one will work).

ssh user@hostname "sudo osascript -e 'tell application \"Finder\" to sleep'"

Note that you do not have to specify "user@hostname" if you have the same username on both systems, but can use just "ssh hostname .... etc."

The key is to escape the quotes that "Finder" is within.

Cheers,
Bev

Bev A. Kupf
Bev's House of Pancakes

Message #7 - Posted 2003/07/08 - Frederick Cheung

On Tue, 8 Jul 2003, Sandman wrote:

Previously, Sander Tekelenburg wrote:

Previously, Sandman wrote:

Is there a way to tell my Mac to go to sleep without having physical access to it? I am using wakeonlan to wake it, but I would like to put it to sleep when I'm done with it - is there a command I can use in SSH for example?

I haven't tried this, but you can use AppleScript to tell the Finder to sleep. So if you'd create an applet like the one below, save it on the remote machine, and trigger it from your ssh session ("open [path to applet]"), I'd think that should work.

tell application "Finder"
delay 30
sleep
end

Possibly, with your ssh session still active, that might immediately wake the remote Mac again. Hence the delay in the script, to give you another 30 seconds (or whatever you prefer) to log out before the sleep command hits. But it may not be necessary.

It should also be possible to do this directly from the terminal. See "man osascript".

Thanks! You got me on the right track. In a SSH session, I can write:

sudo osascript -e 'tell application "Finder" to sleep'

To put the system to sleep. I wish I could, from another system, do:

ssh hostname sudo osascript -e 'tell application "Finder" to sleep'

it's a shell quoting thingy.
ssh hostname sudo osascript -e \'tell application \"Finder\" to sleep\'

should work (at least it does for me)

Fred

Need Help? Have a Question?

Looking for more help, comments, and answers?

Ask your questions on Ask Different. Ask Different is a community of Apple users ready to help.