unixwz0r

itunesnp for OS X (and for my eggdrop bot)

Jul 3rd, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.25 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. ####################################
  4. #chmod +x itunesnp (or whatever you name it)
  5. #cp itunesnp /usr/local/bin
  6. #for OS X only :P
  7. ####################################
  8.  
  9. showHelp () {
  10.     echo "-----------------------------";
  11.     echo "iTunes Command Line Interface";
  12.     echo "-----------------------------";
  13.     echo "Usage: `basename $0` <option>";
  14.     echo;
  15.     echo "Options:";
  16.     echo " status   = Shows iTunes' status, current artist and track.";
  17.     echo " play     = Start playing iTunes.";
  18.     echo " pause    = Pause iTunes.";
  19.     echo " next     = Go to the next track.";
  20.     echo " prev     = Go to the previous track.";
  21.     echo " mute     = Mute iTunes' volume.";
  22.     echo " unmute   = Unmute iTunes' volume.";
  23.     echo " vol up   = Increase iTunes' volume by 10%";
  24.     echo " vol down = Increase iTunes' volume by 10%";
  25.     echo " vol #    = Set iTunes' volume to # [0-100]";
  26.     echo " stop     = Stop iTunes.";
  27.     echo " quit     = Quit iTunes.";
  28. }
  29.  
  30. if [ $# = 0 ]; then
  31.     showHelp;
  32. fi
  33.  
  34. while [ $# -gt 0 ]; do
  35.     arg=$1;
  36.     case $arg in
  37.         "status" ) state=`osascript -e 'tell application "iTunes" to player state as string'`;
  38.             if [ $state = "playing" ]; then
  39.                 artist=`osascript -e 'tell application "iTunes" to artist of current track as string'`;
  40.                 track=`osascript -e 'tell application "iTunes" to name of current track as string'`;
  41.                 echo "Current track $artist:  $track";
  42.             fi
  43.             break ;;
  44.  
  45.         "play"    ) echo "Playing iTunes.";
  46.             osascript -e 'tell application "iTunes" to play';
  47.             break ;;
  48.  
  49.         "pause"    ) echo "Pausing iTunes.";
  50.             osascript -e 'tell application "iTunes" to pause';
  51.             break ;;
  52.  
  53.         "next"    ) echo "Going to next track." ;
  54.             osascript -e 'tell application "iTunes" to next track';
  55.             break ;;
  56.  
  57.         "prev"    ) echo "Going to previous track.";
  58.             osascript -e 'tell application "iTunes" to previous track';
  59.             break ;;
  60.  
  61.         "mute"    ) echo "Muting iTunes volume level.";
  62.             osascript -e 'tell application "iTunes" to set mute to true';
  63.             break ;;
  64.  
  65.         "unmute" ) echo "Unmuting iTunes volume level.";
  66.             osascript -e 'tell application "iTunes" to set mute to false';
  67.             break ;;
  68.  
  69.         "vol"    ) echo "Changing iTunes volume level.";
  70.             vol=`osascript -e 'tell application "iTunes" to sound volume as integer'`;
  71.             if [ $2 = "up" ]; then
  72.                 newvol=$(( vol+10 ));
  73.             fi
  74.  
  75.             if [ $2 = "down" ]; then
  76.                 newvol=$(( vol-10 ));
  77.             fi
  78.  
  79.             if [ $2 -gt 0 ]; then
  80.                 newvol=$2;
  81.             fi
  82.             osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
  83.             break ;;
  84.  
  85.         "stop"    ) echo "Stopping iTunes.";
  86.             osascript -e 'tell application "iTunes" to stop';
  87.             break ;;
  88.            
  89.         "quit"    ) echo "Quitting iTunes.";
  90.             osascript -e 'tell application "iTunes" to quit';
  91.             exit 1 ;;
  92.  
  93.         "help" | * ) echo "help:";
  94.             showHelp;
  95.             break ;;
  96.     esac
  97. done
Advertisement
Add Comment
Please, Sign In to add comment