Skip to content

Instantly share code, notes, and snippets.

@MarcMichalsky
Last active March 5, 2021 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcMichalsky/56b35a5972b08d4e859d479e5309d02a to your computer and use it in GitHub Desktop.
Save MarcMichalsky/56b35a5972b08d4e859d479e5309d02a to your computer and use it in GitHub Desktop.
Logitech Headset battery status on GNOME 3 panel in Ubuntu
#!/usr/bin/env bash
PERCENTAGE="([0-9]*)%$"
CHARGING="(Charging)$"
BATTERY_LEVEL="$(headsetcontrol -b)"
DEVICE="(Found\s)(.*)!"
if [[ $BATTERY_LEVEL =~ $DEVICE ]]; then
DEVICE_NAME="${BASH_REMATCH[2]}"
else
DEVICE_NAME="none"
fi
if [[ $BATTERY_LEVEL =~ $PERCENTAGE ]]; then
STATUS="${BASH_REMATCH}"
elif [[ $BATTERY_LEVEL =~ $CHARGING ]]; then
STATUS="Charging"
else
STATUS="Disconnected"
fi
echo "$STATUS | iconName=audio-headphones-symbolic"
echo "---"
if [[ $DEVICE_NAME != "none" ]]; then
echo "$DEVICE_NAME | iconName=audio-headphones-symbolic"
fi

Install HeadsetControl

Intall C compiler and cmake.

sudo apt-get install build-essential git cmake libhidapi-dev

Clone HeadsetControl from GitHub.

git clone https://github.com/Sapd/HeadsetControl && cd HeadsetControl

Compile code.

mkdir build && cd build
cmake ..
make

Instal HeadsetControl globaly and without root privileges.

sudo make install
sudo udevadm control --reload-rules && sudo udevadm trigger

Install argos

Clone gnome-3.36 branch from GitHub rammie/argos.

git clone -b gnome-3.36 https://github.com/rammie/argos.git

Copy repository into shell extensions folder.

cp -r argos/argos@pew.worldwidemann.com ~/.local/share/gnome-shell/extensions

Restart GNOME Shell with Alt + F2 and entering r.

Enable argos in Tweak Tool.


Prepare argos script

Download argos script.

wget https://gist.githubusercontent.com/MarcMichalsky/56b35a5972b08d4e859d479e5309d02a/raw/ac6802b5f5d50322663adfe3f66a69225f90139d/HS.r.10s.sh
mv HS.r.10s.sh ~/.config/argos/

Make script executable.

sudo chmod +x ~/.config/argos/HS.r.10s.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment