Skip to content

Commit 62238ce

Browse files
authored
Merge pull request #8 from ris58h/get-rid-of-flag-file
Only go to sleep unless the machine is sleeping already
2 parents bc27804 + abcb868 commit 62238ce

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

noclamshell

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

3-
CLAMSHELL=$(ioreg -r -k AppleClamshellState | grep AppleClamshellState | grep Yes)
4-
FLAG_FILE=$TMPDIR/noclamshell.lid.closed.and.sleeping
5-
6-
if [ "$CLAMSHELL" ]; then
7-
if [[ ! -f $FLAG_FILE ]]; then
8-
touch $FLAG_FILE
9-
pmset sleepnow
3+
LID_CLOSED=$(ioreg -r -k AppleClamshellState | grep AppleClamshellState | grep Yes)
4+
if [ "$LID_CLOSED" ]; then
5+
EXTERNAL_DISPLAY_CONNECTED=$(pmset -g powerstate | grep AppleDisplay | grep USEABLE)
6+
if [ "$EXTERNAL_DISPLAY_CONNECTED" ]; then
7+
AWAKE=$(pmset -g powerstate | grep IODisplayWrangler | grep USEABLE)
8+
if [ "$AWAKE" ]; then
9+
pmset sleepnow
10+
fi
1011
fi
11-
else
12-
rm -f $FLAG_FILE
1312
fi

0 commit comments

Comments
 (0)