Created
May 1, 2014 11:24
-
-
Save steveblamey/b456cf7ceb4b84ba6402 to your computer and use it in GitHub Desktop.
NetworkManager script to turn off Gnome screensaver auto-lock on a specifc wireless network
This file contains 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/sh -e | |
# Turn off gnome auto screen-lock when connected to specific wireless networks | |
# USAGE | |
# This script must be placed in /etc/NetworkManager/dispatcher.d | |
# with an appropriate name, e.g. 95gnome-screenlock. | |
# Hat tip, original idea - md, http://blog.bofh.it/debian/id_444 | |
# From NetworkManager | |
IFACE=$1 | |
STATUS=$2 | |
# Define interface, essid and user | |
WIRELESS_IFACE=wlan0 | |
AUTH_ESSID=orchard | |
AUTH_USER=steve | |
# Get session users | |
SESSION_USERS=$(loginctl list-users|sed 's/^ *//'|cut -d' ' -f2) | |
# Exit if not ifup/down on target interface | |
case "$IFACE" in | |
$WIRELESS_IFACE) | |
#Do nothing | |
;; | |
*) | |
exit 0 ;; | |
esac | |
#exit for other users | |
if [[ "$SESSION_USERS" =~ $AUTH_USER ]] | |
then | |
exit 0 | |
fi | |
# return the ESSID of this interface | |
current_essid() { | |
/sbin/iwconfig $1 | sed -nre '/ESSID/s/.*ESSID:"([^"]+)".*/\1/p' | |
} | |
CURRENT_ESSID=$(current_essid $WIRELESS_IFACE) | |
# automatically turn off auto screen-lock when connected to this network, | |
# otherwise turn on auto screen-lock | |
case "$CURRENT_ESSID" in | |
$AUTH_ESSID) | |
su -c "DISPLAY=:0 dconf write /org/gnome/desktop/screensaver/lock-enabled false" $AUTH_USER | |
exit 0 ;; | |
*) | |
su -c "DISPLAY=:0 dconf write /org/gnome/desktop/screensaver/lock-enabled true" $AUTH_USER | |
exit 0 ;; | |
esac | |
exit 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment