Advertisement
BSDG33KCLUB

itunes shell script for OS X useful for weechat and irssi

Jun 9th, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. ####################################
  4. #chmod 755 itunes (or whatever you name it)
  5. #cp itunes /usr/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. echo "iTunes is currently $state.";
  39. if [ $state = "playing" ]; then
  40. artist=`osascript -e 'tell application "iTunes" to artist of current track as string'`;
  41. track=`osascript -e 'tell application "iTunes" to name of current track as string'`;
  42. echo "Current track $artist: $track";
  43. fi
  44. break ;;
  45.  
  46. "play" ) echo "Playing iTunes.";
  47. osascript -e 'tell application "iTunes" to play';
  48. break ;;
  49.  
  50. "pause" ) echo "Pausing iTunes.";
  51. osascript -e 'tell application "iTunes" to pause';
  52. break ;;
  53.  
  54. "next" ) echo "Going to next track." ;
  55. osascript -e 'tell application "iTunes" to next track';
  56. break ;;
  57.  
  58. "prev" ) echo "Going to previous track.";
  59. osascript -e 'tell application "iTunes" to previous track';
  60. break ;;
  61.  
  62. "mute" ) echo "Muting iTunes volume level.";
  63. osascript -e 'tell application "iTunes" to set mute to true';
  64. break ;;
  65.  
  66. "unmute" ) echo "Unmuting iTunes volume level.";
  67. osascript -e 'tell application "iTunes" to set mute to false';
  68. break ;;
  69.  
  70. "vol" ) echo "Changing iTunes volume level.";
  71. vol=`osascript -e 'tell application "iTunes" to sound volume as integer'`;
  72. if [ $2 = "up" ]; then
  73. newvol=$(( vol+10 ));
  74. fi
  75.  
  76. if [ $2 = "down" ]; then
  77. newvol=$(( vol-10 ));
  78. fi
  79.  
  80. if [ $2 -gt 0 ]; then
  81. newvol=$2;
  82. fi
  83. osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
  84. break ;;
  85.  
  86. "stop" ) echo "Stopping iTunes.";
  87. osascript -e 'tell application "iTunes" to stop';
  88. break ;;
  89.  
  90. "quit" ) echo "Quitting iTunes.";
  91. osascript -e 'tell application "iTunes" to quit';
  92. exit 1 ;;
  93.  
  94. "help" | * ) echo "help:";
  95. showHelp;
  96. break ;;
  97. esac
  98. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement