Skip to content

Commit 3c540e8

Browse files
committed
External semaphore to only invoke sleepnow once
Credit goes to @benbosman Fixes #2 I've slightly modified original script, specifically: - removed `sleep 10` altogether, since it's not reliable, and adds unpredictable side effects; - removed parenthesis and ampersand around `pmset sleepnow` so that the script only exits when this command does; - used a temporary file as semaphore. It might attempt to put the sleeping machine to sleep again because of the change in semaphore file name in between script runs (as $TMPDIR changes), but it won't be doing that in two second intervals causing failures. - some cosmetics
1 parent 3bb8710 commit 3c540e8

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@ It periodically checks if lid is closed and puts machine to sleep. Nothing fancy
6161

6262
Author: Phil Pirozhkov
6363

64+
Contributors: @benbosman
65+
6466
License: MIT

noclamshell

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/usr/bin/env bash
22

33
CLAMSHELL=$(ioreg -r -k AppleClamshellState | grep AppleClamshellState | grep Yes)
4+
FLAG_FILE=$TMPDIR/noclamshell.lid.closed.and.sleeping
5+
46
if [ "$CLAMSHELL" ]; then
5-
(pmset sleepnow &); sleep 10
7+
if [[ ! -f $FLAG_FILE ]]; then
8+
touch $FLAG_FILE
9+
pmset sleepnow
10+
fi
11+
else
12+
rm -f $FLAG_FILE
613
fi

0 commit comments

Comments
 (0)