"Sleep" over network

Is there a way to tell my Mac to go to sleep without having physical access to it?
Sandman wrote on :

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?

Sander Tekelenburg replied on :

In article mr-378662.22554407072003@redacted.invalid, Sandman mr@redacted.invalid 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".

Noses replied on :

Sandman mr@redacted.invalid 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.

Sandman replied on :

In article user-021D2A.04281408072003@redacted.invalid, Sander Tekelenburg user@redacted.invalid wrote:

In article mr-378662.22554407072003@redacted.invalid, Sandman mr@redacted.invalid 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 replied on :

In article bedthd$1alh$4@redacted.invalid, Noses noses@redacted.invalid wrote:

Sandman mr@redacted.invalid 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.

Bev A. Kupf replied on :

On Tue, 08 Jul 2003 15:00:45 +0200, Sandman (mr@redacted.invalid) 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@redacted.invalid "sudo osascript -e 'tell application "Finder" to sleep'"

Note that you do not have to specify "user@redacted.invalid" 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

Frederick Cheung replied on :

On Tue, 8 Jul 2003, Sandman wrote:

In article user-021D2A.04281408072003@redacted.invalid, Sander Tekelenburg user@redacted.invalid wrote:

In article mr-378662.22554407072003@redacted.invalid, Sandman mr@redacted.invalid 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