Don’t you wish you could click on i3blocks items and bring up something useful, like a calendar when clicking on the date/time, or a file manager when clicking on the disk usage?
Well, you can! All you have to do is test whether the left mouse button was clicked in the block’s command and spawn a separate command in addition to the regular block command if it was.
For instance, the volume block:
[volume]
label=♪
instance=Master
command=/usr/share/i3blocks/volume "5%" pulse; if [ "$BLOCK_BUTTON" = "1" ]; then pavucontrol > /dev/null 2> /dev/null & disown; fi
interval=once
signal=10
The regular volume command - just to update the text value in the bar - is /usr/share/i3blocks/volume "5%" pulse
.
By tacking ; if [ "$BLOCK_BUTTON" = "1" ]; then pavucontrol > /dev/null 2> /dev/null & disown; fi
after it, the script will also launch pavucontrol
in the background when the command was triggered with the left mouse button.
Similarly, I have the following block commands declared in my .config/i3blocks/config
file:
- Launch Thunar (file browser) when clicking on the free disk space readout:
[disk]
label=🖴 HOME
command=/usr/share/i3blocks/disk; if [ "$BLOCK_BUTTON" = "1" ]; then thunar > /dev/null 2> /dev/null & disown; fi
interval=30
- Launch the Gnome process monitor when clicking on the CPU readout:
[cpu_usage]
label=CPU
command=/usr/share/i3blocks/cpu_usage; if [ "$BLOCK_BUTTON" = "1" ]; then gnome-system-monitor > /dev/null 2> /dev/null & disown; fi
interval=10
min_width=CPU: 100.00%
- Launch the Gnome calendar when clicking on the date & time readout:
[time]
command=date '+%a, %Y-%m-%d %H:%M'; if [ "$BLOCK_BUTTON" = "1" ]; then gnome calendar > /dev/null 2> /dev/null & disown; fi
interval=30