Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Combine bash w/ applescript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Combine bash w/ applescript
Authored by: jeberle-mac on Oct 25, '08 01:01:08PM
I'm glad I found this hint (I'm a former XMMS2 junkie on FreeBSD). You can actually open up the command structure of iTunes directly to the command line. This approach (below) uses a couple short mapping functions, and a mega hint function.

I store this in a file called ~/shell/itunes.sh, and then source it (dot it) from ~/.bashrc, e.g. . ~/shell/itunes.sh


itunes() {
  if [ -z "$1" -o "$1" = '-h' -o "$1" = '--help' ]; then
    itunes-hints
  else
    osascript -e 'tell app "iTunes" to '"$*"
  fi
}

vol() {
  local vol=$(itunes get sound volume)
  if [[ -z "$1" ]]; then
    echo $vol
  elif [[ "$1" = up ]]; then
    itunes set sound volume to $((vol+10))
  elif [[ "$1" = down ]]; then
    itunes set sound volume to $((vol-10))
  elif [[ "$1" =~ ^[0-9]{1,3}$ ]]; then
    itunes set sound volume to "$1"
  else
    echo vol '[up | down | <number>]'
  fi
}

itunes-hints() {
  cat - <<EOS
Usage:
  itunes play
  itunes stop
  itunes playpause
  itunes set mute to 1
  itunes set mute to 0
  itunes quit

  itunes next track
  itunes previous track
  itunes play playlist \"name\"
  itunes play track 3 of current playlist

  itunes get player state
  itunes get player position

  itunes get artist of current track
  itunes get name of current track

  itunes get current stream title
  itunes get current stream URL

  itunes get name of every playlist
  itunes get name of every track in current playlist
  itunes get name of track 3 of current playlist

  itunes set position of window \"iTunes\" to '{0,22}'
  itunes set bounds of window \"iTunes\" to '{0,22,800,600}'
  itunes set visible of window \"iTunes\" to 1

  : ... anything you can tell iTunes via OSA
  : See /Applications/AppleScript/Script Editor

  vol up       - Increase volume by 10%
  vol down     - Decrease volume by 10%
  vol <0-100>  - Set volume from 0 to 100%
EOS
}


[ Reply to This | # ]