This guide shows how to replace the default MPD (Music Player Daemon) module in Archcraft's Polybar with Spotify integration using Spotifyd and Playerctl.
- Archcraft Linux installation
- Polybar configuration (default Archcraft theme)
- Spotify account
- KeepassXC (optional, for secure password management)
yay -S spotifyd playerctl --noconfirmcd ~/.config/openbox/themes/default/polybar
cp modules.ini modules.ini.backupReplace the MPD module with Spotify module:
Find this section (around line 416):
[module/mpd]
type = internal/mpd
# ... (entire MPD configuration)Replace with:
[module/spotify]
type = custom/script
exec = ~/.config/openbox/themes/default/polybar/scripts/spotify-controls.sh
interval = 2
format = <label>
format-background = ${color.ALTBACKGROUND}
format-padding = 1
label = %output%
click-left = playerctl play-pause
click-right = playerctl next
click-middle = playerctl previous
scroll-up = playerctl next
scroll-down = playerctl previousFind the song module (around line 432):
[module/song]
type = internal/mpd
# ... (entire song configuration)Replace with:
[module/spotify-song]
type = custom/script
exec = ~/.config/openbox/themes/default/polybar/scripts/spotify-song.sh
interval = 2
format = <label>
format-font = 5
label = %output%
label-maxlen = 25
label-ellipsis = trueFind line 148:
modules-center = LD date RD dot-alt LD mpd RD sep songReplace with:
modules-center = LD date RD dot-alt LD spotify RD sep spotify-songmkdir -p ~/.config/openbox/themes/default/polybar/scriptsnano ~/.config/openbox/themes/default/polybar/scripts/spotify-controls.shContent:
#!/bin/bash
# Check if Spotify is running
if ! pgrep -x "spotify" > /dev/null; then
echo "๓ฐ Spotify Offline"
exit 0
fi
# Check if playerctl can find spotify
if ! playerctl --player=spotify status > /dev/null 2>&1; then
echo "๓ฐ Spotify Not Playing"
exit 0
fi
# Get current status
STATUS=$(playerctl --player=spotify status 2>/dev/null)
# Define icons
PLAY_ICON="๓ฐ"
PAUSE_ICON="๓ฐค"
PREV_ICON="๓ฐฎ"
NEXT_ICON="๓ฐญ"
# Output the controls based on status
case $STATUS in
"Playing")
echo "${PREV_ICON} ${PAUSE_ICON} ${NEXT_ICON}"
;;
"Paused")
echo "${PREV_ICON} ${PLAY_ICON} ${NEXT_ICON}"
;;
*)
echo "${PREV_ICON} ${PLAY_ICON} ${NEXT_ICON}"
;;
esacnano ~/.config/openbox/themes/default/polybar/scripts/spotify-song.shContent:
#!/bin/bash
# Check if Spotify is running
if ! pgrep -x "spotify" > /dev/null; then
echo "๓ฐ Offline"
exit 0
fi
# Check if playerctl can find spotify
if ! playerctl --player=spotify status > /dev/null 2>&1; then
echo "๓ฐ Not Playing"
exit 0
fi
# Get current status
STATUS=$(playerctl --player=spotify status 2>/dev/null)
# If not playing, show paused or stopped status
if [ "$STATUS" != "Playing" ]; then
echo "๓ฐ $STATUS"
exit 0
fi
# Get song information
ARTIST=$(playerctl --player=spotify metadata artist 2>/dev/null)
TITLE=$(playerctl --player=spotify metadata title 2>/dev/null)
# If we have both artist and title, display them
if [ -n "$ARTIST" ] && [ -n "$TITLE" ]; then
echo "๓ฐ $TITLE"
else
echo "๓ฐ Unknown"
fichmod +x ~/.config/openbox/themes/default/polybar/scripts/spotify-controls.sh
chmod +x ~/.config/openbox/themes/default/polybar/scripts/spotify-song.shmkdir -p ~/.config/spotifyd
nano ~/.config/spotifyd/spotifyd.confContent:
[global]
# Your Spotify username
username = "YOUR_SPOTIFY_USERNAME"
# Use KeepassXC to retrieve password securely (recommended)
password_cmd = "keepassxc-cli show -s -a password /path/to/your/database.kdbx Spotify"
# Or use plain text password (not recommended)
# password = "YOUR_SPOTIFY_PASSWORD"
# The audio backend to use
backend = "pulseaudio"
# The name that will be displayed under the connect tab
device_name = "spotifyd"
# The audio bitrate. 96, 160 or 320 kbit/s
bitrate = 320
# The directory used to cache audio data
cache_path = "/tmp/spotifyd"
# Volume on startup between 0 and 100
initial_volume = "90"
# If set to true, enables volume normalisation between songs
volume_normalisation = true
# The normalisation pregain that is applied for each song
normalisation_pregain = -10
# The displayed device type in Spotify clients
device_type = "computer"-
Create Spotify entry in KeepassXC:
- Open KeepassXC
- Create new entry titled "Spotify"
- Set username to your Spotify username
- Set password to your Spotify password
-
Update spotifyd.conf:
- Replace
YOUR_SPOTIFY_USERNAMEwith your actual username - Update
/path/to/your/database.kdbxwith your KeepassXC database path
- Replace
-
Test the integration:
keepassxc-cli show -s -a password /path/to/your/database.kdbx Spotify
# Test the control script
~/.config/openbox/themes/default/polybar/scripts/spotify-controls.sh
# Test the song script
~/.config/openbox/themes/default/polybar/scripts/spotify-song.sh# Enable and start spotifyd service
systemctl --user enable spotifyd
systemctl --user start spotifydpkill polybar && ~/.config/openbox/themes/default/polybar/launch.sh-
๐ฎ Interactive Controls:
- Left-click: Play/Pause
- Right-click: Next track
- Middle-click: Previous track
- Scroll up/down: Next/Previous track
-
๐ฑ Status Display:
- Shows current song title
- Displays playback status (Playing/Paused)
- Shows offline status when Spotify not running
-
๐ Secure Authentication:
- KeepassXC integration for password management
- No plain text passwords in config files
-
๐จ Visual Consistency:
- Maintains original Archcraft theme styling
- Uses Nerd Font icons for modern look
-
Scripts not working:
# Check if scripts are executable ls -la ~/.config/openbox/themes/default/polybar/scripts/ # Make executable if needed chmod +x ~/.config/openbox/themes/default/polybar/scripts/*.sh
-
Spotify not detected:
# Check if Spotify is running pgrep -x spotify # Check playerctl playerctl --player=spotify status
-
Polybar not updating:
# Restart polybar pkill polybar && ~/.config/openbox/themes/default/polybar/launch.sh
-
Icons not showing:
- Ensure you have Nerd Fonts installed
- Check if your terminal supports Unicode
After completion, your file structure should look like:
~/.config/openbox/themes/default/polybar/
โโโ config.ini # Modified
โโโ modules.ini # Modified
โโโ modules.ini.backup # Backup
โโโ scripts/
โโโ spotify-controls.sh # New
โโโ spotify-song.sh # New
โโโ bluetooth.sh # Existing
~/.config/spotifyd/
โโโ spotifyd.conf # New (optional)
You'll get a fully functional Spotify integration in your Archcraft Polybar that:
- Shows current song title
- Provides interactive playback controls
- Handles offline states gracefully
- Maintains the original theme aesthetics
- Uses secure password management
Tested on: Archcraft with Openbox + Polybar Requirements: spotifyd, playerctl, KeepassXC (optional) Theme: Default Archcraft theme
Feel free to customize the scripts and configuration to match your preferences!