Advertisement
Guest User

mpd-control.sh

a guest
Mar 12th, 2010
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.26 KB | None | 0 0
  1. #!/bin/bash
  2. #=======================================================================================================================
  3. # Description
  4. #   Script to control MPD (music player daemon) using MPC.
  5. # Parameters
  6. #   1 - Command, one of the following:
  7. #         prev
  8. #         next
  9. #         toggle
  10. #         random
  11. #         update
  12. # Version
  13. #   1.00
  14. # History
  15. #   11-03-2010  yktoo  Initial version.
  16. #=======================================================================================================================
  17.  
  18. # Setup vars
  19. cmd=$1
  20. notify_title="MPD Control"
  21.  
  22. #-----------------------------------------------------------------------------------------------------------------------
  23. # Functions
  24. #-----------------------------------------------------------------------------------------------------------------------
  25.  
  26. #-----------------------------------------------------------------------------------------------------------------------
  27. # Displays usage info and exits
  28. # Parameters:
  29. #   none
  30. usage() {
  31.   echo "Usage: $0 [prev|next|toggle|random|update]"
  32.   exit 1      
  33. }
  34.  
  35. #-----------------------------------------------------------------------------------------------------------------------
  36. # Main routine
  37. #-----------------------------------------------------------------------------------------------------------------------
  38.  
  39. unset notify_text notify_icon
  40.  
  41. case "$cmd" in
  42. prev)
  43.   mpc --no-status prev
  44.   notify_text="$(mpc status | sed '1 ! d')"
  45.   notify_icon='media-skip-backward'
  46.   ;;
  47. next)
  48.   mpc --no-status next
  49.   notify_text="$(mpc status | sed '1 ! d')"
  50.   notify_icon='media-skip-forward'
  51.   ;;
  52. toggle)
  53.   mpc --no-status toggle
  54.   if mpc status | grep '\[playing\]' >/dev/null; then
  55.     notify_text="$(mpc status | sed '1 ! d')"
  56.     notify_icon='media-playback-start'
  57.   else
  58.     notify_text='Paused'
  59.     notify_icon='media-playback-pause'
  60.   fi
  61.   ;;
  62. random)
  63.   mpc --no-status random
  64.   notify_text="$(mpc status | grep -o -r 'random: (on|off)')"
  65.   notify_icon='media-playlist-shuffle'
  66.   ;;
  67. update)
  68.   mpc --no-status update
  69.   notify_text='Media library has been reloaded'
  70.   notify_icon='reload'
  71.   ;;
  72. *)
  73.   usage
  74. esac
  75.  
  76. if [[ ! -z "$notify_text" ]]; then
  77.   notify-send -i "$notify_icon" "$notify_title" "$notify_text"
  78. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement