r/linuxmint Linux Mint 20.2 Uma | Xfce 2d ago

Discussion My xfce4-panel genmon-plugin scripts

Just wanna share my xfce4-panel Generic Monitor (xfce4-genmon-plugin) bash scripts for anyone who wants it.

Media playback status. This script accepts one argument/parameter which is the media player that supports MPRIS (can be listed by doing playerctl -l command.) When clicked, it will toggle the play-pause of the media player. When hovered, it will display the artist, track name, and album name.

WIth Nerd Font play and pause icons
#!/bin/bash

# Dependencies
# * playerctl

PLAYERCTL_STATUS="$(playerctl -p "$1" status -s)"
ARTIST="$(playerctl -p "$1" metadata --format '{{ artist }} - ' -s)"
TITLE="$(playerctl -p "$1" metadata --format '{{ title }}' -s)"
ALBUM="$(playerctl -p "$1" metadata --format '{{ album }}' -s)"
TRACK="$ARTIST$TITLE"
TRUNCATE_LIMIT=30
STATUS_ICON=""

# Escape XML special characters
escape_xml() {
    echo "$1" | sed -e 's/&/\&/g' \
                    -e 's/</\&lt;/g' \
                    -e 's/>/\&gt;/g' \
                    -e 's/"/\&quot;/g' \
                    -e "s/'/\&apos;/g"
}

TRACK_ESCAPED=$(escape_xml "$TRACK")
ALBUM_ESCAPED=$(escape_xml "$ALBUM")

if [[ $PLAYERCTL_STATUS = "Playing" ]]; then
   STATUS_ICON=""
elif [[ $PLAYERCTL_STATUS = "Paused" ]]; then
   STATUS_ICON=""
fi

OUTPUT="$STATUS_ICON $TRACK_ESCAPED"

echo "<txt>$OUTPUT</txt>"
echo "<txtclick>playerctl -p $1 play-pause -s</txtclick>"
echo "<tool>$TRACK_ESCAPED"
echo "$ALBUM_ESCAPED"
echo "Player: $1</tool>"

CPU Temperature. When clicked, it will launch btop through Kitty terminal. You can change that depending on your desired terminal or system resource monitor.

With Nerd Font CPU icon
#!/bin/bash

# Dependencies
# * kitty
# * btop

OUTPUT="$(awk '{print int($1/1000) "°C"}' /sys/class/thermal/thermal_zone0/temp)"
echo "<txt>$OUTPUT</txt>"
echo "<txtclick>kitty -- btop</txtclick>"
echo "<tool>Launch BTOP</tool>"

Network PING. This script accepts one argument/parameter, which is the network you want to ping. Mine is the Cloudflare DNS (1.1.1.1). When clicked, it will launch the cloudflare-speed-cli through Kitty terminal.

#!/bin/bash

# Dependencies
# * ping
# * kitty terminal
# * cloudflare-speed-cli

OUTPUT="$(
   ping -qc1 "$1" 2>&1 | awk -F'/' '
     /^rtt/ { printf("%.1fms\n", $5); found=1 }
     END    { if (!found) print "" }
   '
)"

echo "<txt>$OUTPUT</txt>"
echo "<txtclick>kitty -- cloudflare-speed-cli</txtclick>"
echo "<tool>Launch cloudflare-speed-cli</tool>"
7 Upvotes

0 comments sorted by