Skip to content

Instantly share code, notes, and snippets.

@un-def
Created October 8, 2020 17:36
Show Gist options
  • Save un-def/656b91b27a4b881358275a69923b77e7 to your computer and use it in GitHub Desktop.
Save un-def/656b91b27a4b881358275a69923b77e7 to your computer and use it in GitHub Desktop.
Persistent i3blocks blocket displaying VPN connection status
#!/bin/sh
ON='{"full_text": "", "color": "#00ff00"}'
OFF='{"full_text": "", "color": "#ff0000"}'
dbus-send --system \
--print-reply \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.NetworkManager string:PrimaryConnectionType \
| sed -n '1d;s/.*string "vpn"/'"${ON}"'/p;t;s/.*/'"${OFF}"'/p'
dbus-monitor --system "\
type='signal', \
sender='org.freedesktop.NetworkManager', \
interface='org.freedesktop.DBus.Properties', \
member='PropertiesChanged', \
arg0='org.freedesktop.NetworkManager'" \
2> /dev/null \
| stdbuf -oL sed -n '/"PrimaryConnectionType"/{n;s/.*string "vpn"/'"${ON}"'/p;t;s/.*/'"${OFF}"'/p}'
@un-def
Copy link
Author

un-def commented Oct 8, 2020

i3blocks config

...
[vpn]
command=/path/to/i3blocks-vpn.sh
interval=persist
format=json
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment