Wirklich einfache kleine Funktion, aber weiß jemand, wie OS X von Java zu schlafen?Sleep OS X von Java
Prost
Wirklich einfache kleine Funktion, aber weiß jemand, wie OS X von Java zu schlafen?Sleep OS X von Java
Prost
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.
System.exec("osascript -e 'tell application \"System Events\" to sleep'");
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.
Sorry, könnten Sie den Java-Code dafür geben? –