Now the script works on both FreeBSD and Linux, and it exits properly so switching between docked and undocked doesn't cause problems for waybar.