Applescript sleep and wake computer

Discussion in 'Mac Programming' started by Keytachi, Nov 2, 2008.

  1. Keytachi macrumors regular

    Joined:
    Sep 14, 2006
    #1
    Is it possible to create an applescript app. that will put the computer to sleep, and wake it right after when a certain error appears on console?
    Or in a more simpler way, is it possible to make an applescript app that will reactivate the en0 link?

    My computer sometimes (too often) gets an
    Code:
    AppleYukon2: error -  Uncorrectable PCI Express error
    and i need to put it to sleep and wake him to get my internet back (
    Code:
    11/1/08 2:07:45 PM kernel AppleYukon2 - en0 link active, 100-Mbit, full duplex, symmetric flow control enabled port 0 
    )

    fi anyone could help me, it would be awesome.
     
  2. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #2
    At least part of the answer is yes. Here's how you can put your computer to sleep:

    tell application "Finder"
    sleep
    end tell

    that works, at least through 10.4.11. The finder dictionary puts that in the "legacy" suite, so maybe someday it won't work.

    Also, you can:

    tell application "Terminal"
    set textVar to contents of window 1
    end tell

    and then you can parse through textVar to find out if you've received an error message, which would trigger the sleep command.

    Waking it back up, however, I'm not so sure about. The finder "sleep" command means the computer's asleep, so how can Terminal receive a message? Above my paygrade, sorry. But hopefully, this is a start.

    mt
     
  3. Monaj macrumors regular

    Joined:
    May 24, 2009
    #3
    sleep not working for remote computer

    Hi all,

    My problem is simple!

    When I use this script, it works fine:

    tell application "Finder"
    sleep
    end tell

    but when I use this for remote machine, it gives me error as written below it:

    set targetMachine to "eppc://XYZ%20ABC192.168.0.31"
    tell application "Finder" of machine targetMachine
    sleep
    end tell

    error "The variable sleep is not defined." number -2753 from "sleep"

    Can anyone suggest me: am I wrong anywhere? or sleep does not work for remote computer??

    Thanks in advance,

    Monaj
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    If en0 isn't working, how were you planning to tell the remote machine to sleep and then wake? It seems like the link you need to tell it what to do is the same link that isn't working.

    If you're using another interface, such as en1 (WiFi), why not connect internet that way?

    The machine where en0 stops working could run a periodic self-check, and if en0 is down it sleeps itself. Wakeup would still be a problem, unless "wake on LAN" is enabled and some other machine sends it a magic packet. Google keywords: mac os wake on lan.

    The best long-term solution is to find out why en0 stops working and fix it. Since you haven't identified the model or configuration, I suggest googling: AppleYukon2.
     
  5. renaultssoftwar macrumors newbie

    Joined:
    Jan 1, 2010
    #5
    Sleep Remote Machine

    Use System Events to sleep a machine.
     

Share This Page