Polybar modules (Zoom and service)

Some time ago I wrote several i3 blocklets, in particular Zoom Dunst notification and a service blocklet (to be able easily to enable/disable services). And since I moved from i3blocks to polybar, I had slightly to adjust the scripts.

Zoom Dunst module

I already wrote a short post about the Zoom dunst module. Here is just a slightly adjusted version for polybar.

To integrate the module, just add the snippet to your polybar modules and adjust the path to the zoom.sh script.

1
2
3
4
5
[module/zoom]
type = custom/script
exec = ~/polybar-scripts/zoom.sh
interval = 5
label = %output% Zoom

zoom.sh script

The zoom.sh file looks like that

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

DUNST_TIMEOUT=${DUNST_TIMEOUT:-3} # duration in seconds
DUNST_URGENCY=${DUNST_URGENCY:-"low"} # low, normal or critical

enable () {
touch /tmp/i3zoom.lock
notify-send -u ${DUNST_URGENCY} -t ${DUNST_TIMEOUT}000 Zoom "Sharing mode activated"
sleep ${DUNST_TIMEOUT}
notify-send DUNST_COMMAND_PAUSE
}

disable () {
rm /tmp/i3zoom.lock
notify-send DUNST_COMMAND_RESUME
}

xwininfo -name as_toolbar >/dev/null 2>&1
if [ $? -eq 0 ]; then
if ! [ -f "/tmp/i3zoom.lock" ]; then
enable
echo "%{F#ff0000}"
else
echo "%{F#ff0000}"
fi

else
if [ -f "/tmp/i3zoom.lock" ]; then
disable
fi
echo "%{F#ff0000}"
fi

Service module

The service module is an easy integration of your Linux service, which you can enable/disable/toggle. E.g. I use it often to enable/disable the OpenVPN service or other frequently toggled services.

It can be turned on/off just by clicking on the name of the service.

To integrate the module, just add the snippet to your polybar modules and adjust the path to the service.sh script.

1
2
3
4
5
6
7
8
[module/service]
type = custom/script
exec = ~/polybar-scripts/service.sh
interval = 5
click-middle = ~/polybar-scripts/service.sh toggle &
click-left = ~/polybar-scripts/service.sh enable &
click-right = ~/polybar-scripts/service.sh disable &
label = %output%

service.sh script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

SERVICE_NAME="openvpn"

if [ "$(systemctl is-active "$SERVICE_NAME")" != "active" ]
then
echo '%{F#ff0000} '$SERVICE_NAME
else
echo '%{F#00ff00} '$SERVICE_NAME
fi


enable () {
sudo systemctl start "$SERVICE_NAME"
}

disable () {
sudo systemctl stop "$SERVICE_NAME"
}

toggle () {
if [ "$(systemctl is-active $SERVICE_NAME)" != "active" ]
then
sudo systemctl start $SERVICE_NAME
else
sudo systemctl stop $SERVICE_NAME
fi
}

"$@"