Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save milanglacier/31157952fed31e94507ba97e67189e79 to your computer and use it in GitHub Desktop.
Save milanglacier/31157952fed31e94507ba97e67189e79 to your computer and use it in GitHub Desktop.
Minimal Polybar Setup with Music Display and Playerctl Controls

Polybar appearance:

Screenshot 2024-11-12 at 23 56 42

In your polybar config, the relevant config part is:

~/.config/polybar/config.ini

[bar/toph]

# Make sure you use a nerd font to display icons
# Note that github webui cannot render nerd icons in the following script
# leaving those icons shown as spaces
font-0 = Monofur Nerd Font:size=22;4

modules-left = playerctl

[module/playerctl]
type = custom/script
# refresh music info every 3 seconds, check if player is active every 2.5 seconds
interval = 3
interval-if = 2.75

exec = ~/.config/polybar/bin/music-info.sh &
# only execute the script if the the player is active
execif = ~/.config/polybar/bin/playerctl-status.sh &


format-prefix = ""
format-prefix-foreground = ${colors.Rose}

label = %{A1:playerctl play-pause &:}󰐎%{A}  %output:0:25:% %{A1:playerctl previous &:}󰒮%{A} %{A1:playerctl next &:}󰒭%{A}

~/.config/polybar/bin/music-info.sh

#!/bin/sh

player_status="$(playerctl status 2> /dev/null)"

if [[ "$player_status" = "Playing" || "$player_status" = "Paused" ]]; then
    echo "$(playerctl metadata artist) - $(playerctl metadata title)"
else
    echo ""
fi

~/.config/polybar/bin/playerctl-status.sh

#!/bin/sh
player_status="$(playerctl status 2> /dev/null)"

if [[ "$player_status" = "Playing" || "$player_status" = "Paused" ]]; then
    exit 0
else
    exit 1
fi

Attribution: polybar-scripts-player-mpris-simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment