2009-06-10 6 views

Répondre

1

Voir: Making Mac OS X sleep from the command line

Créer un script qui suit:

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

et utiliser pour exec il.

+0

Désolé pourriez-vous donner le code java pour cela? –

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()); 
    } 
} 

Pour une raison quelconque alors que je faisais cela ne fonctionnait pas sans l'exécuter par bash.