Question: I recently restarted after an update on 15.10, and now the keyboard on my laptop (Lenovo Thinkpad Yoga) doesn't work. I can't even ctrl-alt-[N] to get to a virtual terminal, nor does a USB keyboard work. The keyboard *does* work in BIOS setup and GRUB mode, but that's it. Also, the touchscreen stopped working at the same time. I had also changed a line in a xorg.conf.d file, affecting the synaptics driver prior to this, but I can't work out why this would kill the keyboard and touchscreen.

Answer: 
NetworkManager includes an `nmcli` program, which has a `monitor` command. Here is what its output looks like for me when I disconnect then connect to a Wi-Fi access point:

```
$ nmcli monitor
There's no primary connection
wlp4s0: unavailable
Networkmanager is now in the 'disconnected' state
wlp4s0: disconnected
wlp4s0: using connection 'CyberShadowPC'
wlp4s0: connecting (prepare)
Networkmanager is now in the 'connecting' state
wlp4s0: connecting (configuring)
wlp4s0: connecting (need authentication)
wlp4s0: connecting (prepare)
wlp4s0: connecting (configuring)
wlp4s0: connecting (getting IP configuration)
wlp4s0: connecting (checking IP connectivity)
wlp4s0: connecting (starting secondary connections)
wlp4s0: connected
Networkmanager is now in the 'connected' state
'CyberShadowPC' is now the primary connection

```

It looks like it should be easy to parse its output and run appropriate actions as necessary. Here's a bash script which runs a command when a NetworkManager connection becomes the active primary one:

```
#!/bin/bash
set -euo pipefail

connection_name=CyberShadowPC
command=(notify-send "Connected to $connection_name!")

LC_ALL=C nmcli monitor | \
    while read -r line
    do
        if [[ "$line" == "'$connection_name' is now the primary connection" ]]
        then
            "${command[@]}"
        fi
    done

```
While it's certainly possible to use `dbus` , personally I'd go with simple bash while loop + awk

```
while [ "$(iwconfig 2> /dev/null |  awk '/Access Point/ && /XX:YY:ZZ:11:22:33/ {print "true" }')" != "true" ]; do : ; sleep 0.25 ;done ; echo DONE

```

What is happening there ? While loop keeps running, testing output of `iwconfig` filtered out with `awk`. So far as the `awk` doesn't find the mac address of the access that you want to connect to, loop continues running. As soon as `awk` sees that you've associated with that particular AP , the test condition `[ "String1" != "String2" ]` becomes false, loop breaks , and goes on to the `echo DONE` command. Of course , `echo DONE` is what can be replaced with the program that you want to run.

This command can be ran manually or placed into a script, and the script added to the Startup Application list.

Simple, straightforward, and does the job. Like I said in the beginning, it is possible to use dbus , but is not as simple.