Last active
September 22, 2015 15:09
-
-
Save Shou/55c02ea1b19dbc0bd9d0 to your computer and use it in GitHub Desktop.
GNOME Wi-Fi auto-wake and unlock screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# SETUP | |
# Device MAC address | |
MAC="FF:FF:FF:FF:FF:FF" | |
# IP subnet range | |
RANGE="192.168.0.0/27" | |
timeout=1.0 | |
setTimeout() { | |
timeout="$(( $timeout * 1.1 ))" | |
if [ 1 -eq "$(echo $timeout '>' 120 | bc)" ]; then | |
timeout=120.0 | |
fi | |
} | |
while true; do | |
# network device exists | |
# Requires nmap to be part of user's NOPASSWD sudoers commands | |
exists=$(sudo nmap -sP $RANGE | grep -iA 1 $MAC) | |
if [ ! -z "$exists" ]; then | |
# screensaver time active | |
active=$(qdbus org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.GetActiveTime) | |
if ! [ "$active" = "0" ]; then | |
echo "Device unlocking. Screensaver was active for $active seconds." | |
gnome-screensaver-command -d | |
xset dpms force on | |
# Reset timeout | |
timeout=1.0 | |
else | |
setTimeout | |
# "Device found but screen is not locked ($timeout sleep)" | |
sleep $timeout | |
fi | |
else | |
setTimeout | |
# "Device not found ($timeout sleep)" | |
sleep $timeout | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment