Connect automatically (and immediately) to a hidden WiFi

A minor annoyance on with wireless networking at home seems to easily resolved. I'm very happy that NetworkManager offers a CLI that works together with the GNOME-NetworkManager-applet. cnetworkmanager does, or at least did not work for me.

The WiFi at home uses a hidden ESSID and it looks like NetworkManager does not connect to this automatically. Well, that's not completely correct, it just takes a lot of time for NetworkManager to attempt to connect. It's unclear to me why NetworkManager sometimes connect me automatically, and sometimes it seems to take ages and manually connecting to the hidden wireless network is quicker.

This little script ~/bin/nm-connect-me.sh forces NetworkManager to connect to the hidden WiFi when wireless is enabled and there is no connection yet:
#!/bin/sh
#
# Automatically try to connect to 'MyWiFi' when WiFi is enabled
#

# the output of nmcli should be in English
LC_ALL=C

# loop for a while until NetworkManager is accepting commands
while [ "$(nmcli -t -f WIFI,STATE nm)" = 'enabled:disconnected' ]
do
nmcli con up id MyWiFi
sleep 5
done

exit 0

After making the script executable and adding it as a startup application over xfce4-session-settings, the network connection is established immediately when I login. It really bids me a little more comfort when turning on my laptop.

The changelog from the NetworkManager package shows that nmcli was added about one year ago! Such a shame that I only found out about it recently...
Share Comments
comments powered by Disqus