From a BASH script I want to get user input and change system settings, in a loop. I first tried cocoaDialog but that has a fatal flaw: the dialogs are always on top of other windows.
Ideally, I could throw up a dialog with "set sleep mode" and "set awake mode" (for toggling the "Prevent computer from sleeping automatically when the display is off" setting) buttons and the dialog/window would stay put when buttons are pressed. In the case of cocoaDialog, I had to put up a new dialog each time a button was pressed. It would have been fine, but aside from the above problem already mentioned, putting up a new dialog positions it in the middle of the screen and not where the old one was (and cocoaDialog doesn't have positioning arguments for dialogs).
Anyone know of a solution? I suspect AppleScript would work, but it is so complex and I've not been able to find suitable examples I could copy/modify.
Thanks.
Best Answer
I've found two solutions. The best one is second.
Solution #1: use Tcl/Tk:
where prevent_computer_sleep just does
sudo pmset sleep 0
and allow_computer_sleep doessudo pmset sleep 1
.Solution #2: modify KeepingYouAwake to use system sleep and not display sleep: my fork of KeepingYouAwake.