Guest User

applemusic.10s.sh

a guest
Aug 19th, 2020
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.10 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Get current Music status with play/pause button
  4. #
  5. # based on Spotify script by Jason Tokoph (jason@tokoph.net),
  6. # tweaked by Dan Turkel (daturkel@gmail.com),
  7. # additionally tweaked by Aleš Farčnik (@alesf)
  8. # additionally tweaked by Jeffrey Munowitch (@jmunowitch)
  9. # additionally tweaked by Jason Snell (jsnell@sixcolors.com)
  10. #
  11. # Shows current track information from Music
  12. # 10 second refresh might be a little too quick. Tweak to your liking.
  13.  
  14. # metadata
  15. # <bitbar.title>Music Now Playing - Antony's Version</bitbar.title>
  16. # <bitbar.version>v1.1</bitbar.version>
  17. # <bitbar.author>Dan Turkel, Jason Tokoph, Aleš Farčnik, Jeffrey Munowitch</bitbar.author>
  18. # <bitbar.author.github>daturkel</bitbar.author.github>
  19. # <bitbar.desc>Display currently playing Music song with artwork. Play/pause, skip forward, skip backward.</bitbar.desc>
  20. # <bitbar.image>http://i.imgur.com/lBfoFdY.png</bitbar.image>
  21.  
  22. if [ "$1" = 'launch' ]; then
  23.   osascript -e 'tell application "Music" to activate'
  24.   exit
  25. fi
  26.  
  27. if [ "$1" = 'open' ]; then
  28.   osascript -e 'tell application "Music" to reopen'
  29.   osascript -e 'tell application "Music" to activate'
  30.   exit
  31. fi
  32.  
  33. if [ "$(osascript -e 'application "Music" is running')" = "false" ]; then
  34.   echo "♫ | size=12"
  35.   echo "---"
  36.   echo "Music is not running"
  37.   echo "Launch Music | bash='$0' param1=launch terminal=false"
  38.   exit
  39. fi
  40.  
  41. if [ "$1" = 'playpause' ]; then
  42.   osascript -e 'tell application "Music" to playpause'
  43.   exit
  44. fi
  45.  
  46. if [ "$1" = 'previous' ]; then
  47.   osascript -e 'tell application "Music" to previous track'
  48.   exit
  49. fi
  50.  
  51. if [ "$1" = 'next' ]; then
  52.   osascript -e 'tell application "Music" to next track';
  53.   exit
  54. fi
  55.  
  56. BitBarDarkMode=${BitBarDarkMode}
  57. if [ "$BitBarDarkMode" ]; then
  58.   COLOR0="#666666"
  59.   COLOR1="#ffffff"
  60.   COLOR2="#666666"
  61.   COLOR3="#333333"
  62. else
  63.   COLOR0="#333333"
  64.   COLOR1="#000000"
  65.   COLOR2="#666666"
  66.   COLOR3="#999999"
  67. fi
  68.  
  69. state=$(osascript -e '
  70. try
  71.  tell application "Music"
  72.    with timeout 3 seconds
  73.      player state as string
  74.    end timeout
  75.  end tell
  76. on error errText
  77.  "not available"
  78. end try  
  79. ');
  80. if [ "$state" = "not available" ]; then
  81.   echo "♫ | size=12"
  82.   echo "---"
  83.   echo "Music is not available"
  84.   exit
  85. elif [ "$state" = "paused" ]; then
  86.   echo ""
  87.   exit
  88. fi
  89.  
  90. track=$(osascript -e'
  91. try
  92. tell application "Music" to name of current track as string
  93. on error errText
  94.  "no track selected"
  95. end try
  96. ');
  97.  
  98. artist=$(osascript -e'
  99. try
  100.     tell application "Music" to artist of current track as string
  101. on error errText
  102.    ""
  103. end try
  104. ');
  105.  
  106. album=$(osascript -e'
  107. try
  108.     tell application "Music" to album of current track as string
  109. on error errText
  110.    ""
  111. end try
  112. ');
  113.  
  114. year=$(osascript -e'
  115. set theYear to "0"
  116. tell application "Music"
  117.     try
  118.         set theYear to (year of current track as string)
  119.     on error errText
  120.         ""
  121.     end try
  122. end tell
  123. if theYear = "0" then
  124.     return ""
  125. else
  126.     return ("(" & theYear & ")")
  127. end if
  128. ');
  129.  
  130.  
  131. if [ "$track" != "no track selected" ]; then
  132.     echo "$track - $album $year - $artist | color=$COLOR2 size=12"
  133. else
  134.     echo "♫ ◼︎ | color=$COLOR0 size=12"
  135. fi
  136.  
Add Comment
Please, Sign In to add comment