2009-06-10 14 views

Antwort

1

See: Making Mac OS X sleep from the command line

Erstellen Sie ein Skript mit dem folgenden:

#!/bin/bash 
osascript << EOT 
tell application "System Events" 
    sleep 
end 
EOT 

Und Verwendung System es exec.

+0

Sorry, könnten Sie den Java-Code dafür geben? –

2
System.exec("osascript -e 'tell application \"System Events\" to sleep'"); 
-1
 
public void gotoSleep(){ 
    try{ 
     logger.finer("Zzz..."); 

     if (preferences.getOS().equals("OSX") == true){ 
     Process p = Runtime.getRuntime().exec 
      ("/bin/bash"); 
     String command = "osascript -e 'tell application \"System Events\"' " 
      + " -e \"sleep\" -e 'end tell'"; 

     OutputStream stdin = p.getOutputStream(); 
     stdin.write(command.getBytes()); 
     stdin.flush(); 
     stdin.close(); 
     } 

    }catch(Exception e) { 
     logger.warning(e.toString()); 
    } 
} 

Aus irgendeinem Grund, während ich es tat es nicht ohne sie durch bash Ausführung funktionierte.