Skip to content

Instantly share code, notes, and snippets.

@steveblamey
Created May 1, 2014 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveblamey/b456cf7ceb4b84ba6402 to your computer and use it in GitHub Desktop.
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
#!/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