Last active
September 9, 2024 23:37
-
-
Save SwiftyAlex/9c4fd5a5d0c4c2928eab3e03c0ee310f to your computer and use it in GitHub Desktop.
Bartender script to check for Spotify or Apple Music
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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