Put your mac to rest via ssh

July 17, 2008 by Michael

Sometimes my Macbook decides to wake up from his sleep (a.k.a hibernation). Most of the times i notice this at work when my emails disappear from my imap inbox as Mail.app applies his rules.

As i do not have Apple Remote Desktop or any other VNC server enabled on my Macbook, i do have a problem.

I can vpn into my home and i can ssh into the Macbook, so i came up with the following solution:

Put the following three lines into a plain textfile, i.e. “sleep.txt” and save it somewhere:

tell application "Finder"
  sleep
end tell

Then, open Terminal.app, change to the directory you saved the file in and execute:

osascript sleep.txt

Your ssh connection will then timeout and the Mac sleeps.

Stupid me forgot that ssh can execute remote commands: From your workmachine execute

ssh my_home_computer 'osascript sleep.txt'

and you’re done. Thanks “tante” for reminding me ๐Ÿ™‚

Alternatively, you can achieve similar with Mail.app itself, have a look at the solution here, but i like mine better.

6 comments

  1. tante wrote:

    Just as another hint some people don’t know:
    You can give SSH the command it is supposed to run on the remote machine directly. An example:
    “ssh my_home_computer hostname” this runs the command “hostname” on the machine “my_home_computer”. Just add a SSH key that only allows your one sleep command and you can put it all into a little icon/shortcut thingy or a local script on your work machine. Saves you some typing ๐Ÿ˜‰

    Posted on July 17, 2008 at 2:26 PM | Permalink
  2. tante wrote:

    Oh yeah and the SSH connection automatically closes itself after running the command so you don’t have some shell behaving weird due to timeouts ๐Ÿ˜‰

    Posted on July 17, 2008 at 2:26 PM | Permalink
  3. Michael wrote:

    You’re certainly right ๐Ÿ™‚ Thanks for reminding me…

    I was to upset about the stupid macbook waking up. Don’t know what causes it, at least wol doesn’t work over wlan afaik…
    Sometimes it comes back on if i switch on the amplifier, maybe its something with power peaks.

    But hey, it’s nothing new anymore being upset about Apple products for me.

    Posted on July 17, 2008 at 2:33 PM | Permalink
  4. tante wrote:

    Well WOL needs a “somewhat-up” network device, I don’t know if Wireless network devices can be in that state. If they can be you should be able to turn it off in the BIOS.

    If it is power spikes you could put one of those protection gimmicks between the computer and the power thingamajing which would of course just be a waste of money if it’s something else ๐Ÿ˜‰

    Posted on July 17, 2008 at 2:41 PM | Permalink
  5. Michael wrote:

    I think it’s something else, it “works” even the notebook is on battery… I guess Mac OS X is monitoring in some weird way the line-out port… And yeah, i’m afraid of the question and so i answer it: OS X is still around due to my decision way back to buy into the DRM crapped music. Stupid me, once again. Not that much songs but some albums i couldn’t get elsewhere.

    Posted on July 18, 2008 at 2:31 PM | Permalink
  6. tante wrote:

    Poor you, I don’t envy you with a problem like that ๐Ÿ˜‰

    Posted on July 18, 2008 at 2:39 PM | Permalink
Post a Comment

Your email is never published. We need your name and email address only for verifying a legitimate comment. For more information, a copy of your saved data or a request to delete any data under this address, please send a short notice to michael@simons.ac from the address you used to comment on this entry.
By entering and submitting a comment, wether with or without name or email address, you'll agree that all data you have entered including your IP address will be checked and stored for a limited time by Automattic Inc., 60 29th Street #343, San Francisco, CA 94110-4929, USA. only for the purpose of avoiding spam. You can deny further storage of your data by sending an email to support@wordpress.com, with subject โ€œDeletion of Data stored by Akismetโ€.
Required fields are marked *