This is a widget for Waybar that displays your currently playing song title and artist from either Spotify or Strawberry, automatically detecting the most relevant player to show.
- Intelligent Player Detection: Automatically detects and displays the music player that is actively "Playing", prioritizing it over any that are "Paused".
- Sticky Last Active Player: To prevent the display from flickering, the widget "sticks" to the last player you were actively listening to. It will continue to show that player's info when paused, until you start playing music on a different player.
- Multi-Player Support: Works with both Spotify and Strawberry Music Player.
- Dynamic Player Controls: Use
on-clickandon-scrollevents in Waybar to control playback (play/pause, next, previous) on whichever player is currently active. - Customizable: Shows different icons for each player ( for Spotify, 🍓 for Strawberry).
- Spotify:
spotify_player - Strawberry:
strawberry
First, make sure you have jq and playerctl installed.
- On Arch Linux:
sudo pacman -S jq playerctl - On Debian/Ubuntu:
sudo apt install jq playerctl
This is the most reliable way to install the widget.
First, add "custom/music" to your modules-center (or left/right) array in ~/.config/waybar/config.jsonc.
Then, add the following module definition to your config file.
Note: The exec-if condition is important. It ensures the script only runs when a supported player is active, saving resources.
"custom/music": {
"format": "{}",
"exec": "/path/to/your/script/waybar-spotify-widget.sh",
"return-type": "json",
"interval": 1,
"exec-if": "pgrep spotify || pgrep strawberry",
"on-click": "/path/to/your/script/waybar-spotify-widget.sh play-pause",
"on-scroll-up": "/path/to/your/script/waybar-spotify-widget.sh next",
"on-scroll-down": "/path/to/your/script/waybar-spotify-widget.sh previous",
"tooltip": true
},Important: Remember to replace /path/to/your/script/ with the actual absolute path to the waybar-spotify-widget.sh script.
An installer script is included for convenience, but it can be a bit finicky. It attempts to modify your Waybar configuration file automatically, which may not work reliably with all setups. The manual method is strongly recommended.
If you'd like to try it, navigate to the repository directory and run the script:
./Install.shThis will back up your existing Waybar config, then attempt to add the necessary module definition and add it to your modules-center array.
It should be pretty easy to add music players other than spotify and strawberry to the script. You just need to add your program's name to the find_relevant_player tab
find_relevant_player() {
PLAYERS="spotify_player strawberry spotify"You could also add a custom unicode for the music player (one differing from the default 🎵 one).
if [[ "$RELEVANT_PLAYER" == *"spotify"* ]]; then
icon="" # Spotify icon
class="custom-spotify"
elif [[ "$RELEVANT_PLAYER" == *"strawberry"* ]]; then
icon="🍓" # Strawberry icon
class="custom-strawberry"
elif [[ "$RELEVANT_PLAYER" == *"yourmusicplayer"* ]]; then
icon=" " # Put your unicode here
class="custom-yourmusicplayer"
else
icon="🎵" # Generic music icon
class="custom-music"
fi