Skip to content

Instantly share code, notes, and snippets.

@SwiftyAlex
Last active September 9, 2024 23:37
Show Gist options
  • Save SwiftyAlex/9c4fd5a5d0c4c2928eab3e03c0ee310f to your computer and use it in GitHub Desktop.
Save SwiftyAlex/9c4fd5a5d0c4c2928eab3e03c0ee310f to your computer and use it in GitHub Desktop.
Bartender script to check for Spotify or Apple Music
#!/bin/bash
# Function to check if an app is playing
check_playing() {
if pgrep -x "$1" > /dev/null; then
if osascript -e "tell application \"$1\" to player state" | grep -q "playing"; then
return 0 # 0 means true in Bash
fi
fi
return 1 # 1 means false in Bash
}
# Check Apple Music
if check_playing "Music"; then
echo 1
exit 0
fi
# Check Spotify
if check_playing "Spotify"; then
echo 1
exit 0
fi
# If neither is playing
echo 0
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment