Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Get current Music status with play/pause button
- #
- # based on Spotify script by Jason Tokoph (jason@tokoph.net),
- # tweaked by Dan Turkel (daturkel@gmail.com),
- # additionally tweaked by Aleš Farčnik (@alesf)
- # additionally tweaked by Jeffrey Munowitch (@jmunowitch)
- # additionally tweaked by Jason Snell (jsnell@sixcolors.com)
- #
- # Shows current track information from Music
- # 10 second refresh might be a little too quick. Tweak to your liking.
- # metadata
- # <bitbar.title>Music Now Playing - Antony's Version</bitbar.title>
- # <bitbar.version>v1.1</bitbar.version>
- # <bitbar.author>Dan Turkel, Jason Tokoph, Aleš Farčnik, Jeffrey Munowitch</bitbar.author>
- # <bitbar.author.github>daturkel</bitbar.author.github>
- # <bitbar.desc>Display currently playing Music song with artwork. Play/pause, skip forward, skip backward.</bitbar.desc>
- # <bitbar.image>http://i.imgur.com/lBfoFdY.png</bitbar.image>
- if [ "$1" = 'launch' ]; then
- osascript -e 'tell application "Music" to activate'
- exit
- fi
- if [ "$1" = 'open' ]; then
- osascript -e 'tell application "Music" to reopen'
- osascript -e 'tell application "Music" to activate'
- exit
- fi
- if [ "$(osascript -e 'application "Music" is running')" = "false" ]; then
- echo "♫ | size=12"
- echo "---"
- echo "Music is not running"
- echo "Launch Music | bash='$0' param1=launch terminal=false"
- exit
- fi
- if [ "$1" = 'playpause' ]; then
- osascript -e 'tell application "Music" to playpause'
- exit
- fi
- if [ "$1" = 'previous' ]; then
- osascript -e 'tell application "Music" to previous track'
- exit
- fi
- if [ "$1" = 'next' ]; then
- osascript -e 'tell application "Music" to next track';
- exit
- fi
- BitBarDarkMode=${BitBarDarkMode}
- if [ "$BitBarDarkMode" ]; then
- COLOR0="#666666"
- COLOR1="#ffffff"
- COLOR2="#666666"
- COLOR3="#333333"
- else
- COLOR0="#333333"
- COLOR1="#000000"
- COLOR2="#666666"
- COLOR3="#999999"
- fi
- state=$(osascript -e '
- try
- tell application "Music"
- with timeout 3 seconds
- player state as string
- end timeout
- end tell
- on error errText
- "not available"
- end try
- ');
- if [ "$state" = "not available" ]; then
- echo "♫ | size=12"
- echo "---"
- echo "Music is not available"
- exit
- elif [ "$state" = "paused" ]; then
- echo ""
- exit
- fi
- track=$(osascript -e'
- try
- tell application "Music" to name of current track as string
- on error errText
- "no track selected"
- end try
- ');
- artist=$(osascript -e'
- try
- tell application "Music" to artist of current track as string
- on error errText
- ""
- end try
- ');
- album=$(osascript -e'
- try
- tell application "Music" to album of current track as string
- on error errText
- ""
- end try
- ');
- year=$(osascript -e'
- set theYear to "0"
- tell application "Music"
- try
- set theYear to (year of current track as string)
- on error errText
- ""
- end try
- end tell
- if theYear = "0" then
- return ""
- else
- return ("(" & theYear & ")")
- end if
- ');
- if [ "$track" != "no track selected" ]; then
- echo "$track - $album $year - $artist | color=$COLOR2 size=12"
- else
- echo "♫ ◼︎ | color=$COLOR0 size=12"
- fi
Add Comment
Please, Sign In to add comment