Subscribe to
Posts
Comments
NSLog(); Header Image

iTunes Shell Script

I was on a mailing list and the topic of AppleScript came up. I forget why, but I posted one of my "Terminal AppleScripts" (usig osascript) like those I mentioned in iTunes Remote via SSH. The end result? A better script. See the full entry for the source.

Kudos to Lu Lewis Butler for cobbling together the more impressive script. You can see it below or here.

#!/bin/sh
# itunes script version 1.0.2
# By Lewis Butler (lbutler @ southgaylord . com)
# based on an idea of Erik J. Barzeski's  (erik @ barzeski . com)
#
# save this script somewhere in your path and give it
# execute permissions.
# http://syth.serveftp.net/itunes
case $1 in
nt)
osascript \
    -e "tell application \"iTunes\""  \
    -e "    set x to \"\"" \
    -e "    if player state is not playing then" \
    -e "        play" \
    -e "        set y to name of current track & \" by \" & artist of current track & \"\"" \
    -e "        set result to  y" \
    -e "    else" \
    -e "        next track" \
    -e "        set y to name of current track & \" by \" & artist of current track & \"\"" \
    -e "        set result to y" \
    -e "    end if" \
    -e "end tell" 
;;
pt)
osascript \
    -e "tell application \"iTunes\""  \
    -e "    set x to \"\"" \
    -e "    if player state is not playing then" \
    -e "        play" \
    -e "        set y to name of current track & \" by \" & artist of current track & \"\"" \
    -e "        set result to  y" \
    -e "    else" \
    -e "        previous track" \
    -e "        set y to name of current track & \" by \" & artist of current track & \"\"" \
    -e "        set result to y" \
    -e "    end if" \
    -e "end tell" 
;;
name)
osascript \
    -e "tell application \"iTunes\"" \
    -e "  if player state is not playing then "\
    -e  "    set result to \"iTunes is not playing a song\"" \
    -e "  else" \
    -e "    set x to name of current track & \" by \" & artist of current track & \" from \" & album of current track & \"\"" \
    -e "    set result to x " \
    -e "  end if" \
    -e "end tell"
;;
ff)
osascript \
    -e "tell application \"iTunes\"" \
    -e "  fast forward" \
    -e "end tell"
;;
pause)
osascript \
    -e "tell application \"iTunes\" to pause" 
;;
play)
osascript \
    -e "tell application \"iTunes\" to play" 
;;
pp)
osascript \
    -e "tell application \"iTunes\" to playpause"
;;
ns)
osascript \
    -e "tell application \"iTunes\"" \
    -e "  set mytrack to (first track of view of front window whose name contains \"$2\")" \
    -e "  play mytrack" \
    -e "    set x to name of current track & \" by \" & artist of current track & \"\"" \
    -e "    set result to x " \
    -e "end tell"
;;
as)
osascript \
    -e "tell application \"iTunes\"" \
    -e "  set mytrack to (first track of view of front window whose album contains \"$2\")" \
    -e "  play mytrack" \
    -e "    set x to name of current track & \" by \" & artist of current track & \"\"" \
    -e "    set result to x " \
    -e "end tell"
;;
na)
osascript \
    -e "tell application \"iTunes\"" \
    -e "  set mytrack to (first track of view of front window whose (name contains \"$2\" and artist contains \"$3\") )" \
    -e "  play mytrack" \
    -e "    set x to name of current track & \" by \" & artist of current track & \"\"" \
    -e "    set result to x " \
    -e "end tell"
;;
'')
 echo "iTunes Helper script V1.0"
 echo "itunes pp              : toggle itunes between play and pause"
 echo "itunes nt              : next track"
 echo "itunes pt              : previous track"
 echo "itunes ff              : fast forward"
 echo "itunes pause           : pause play"
 echo "itunes name            : display name of current track being played"
 echo "itunes play            : start playing "
 echo "itunes ns name         : find song containing \"name\" and play"
 echo "itunes as test         : find album containing \"test\" and play"
 echo "itunes na name artist  : find song containing \"name\" and artist \"artist\""
esac
###########
#
# VERSION HISTORY
#
# 1.0 initial release
# 1.0.1 added name disply to the ns and as flags
# 1.0.2 added na switch

5 Responses to "iTunes Shell Script"

  1. Neato--that will come in handy if I ever get my hypothetical MP3 server going :-)!

  2. 2003/05/22 16:43

    iTunes shell script

  3. I still think mine is better since it uses precompiled AppleScripts for speed and power that provides.

  4. Quick links

    ongoing · The RDF.net Challenge File Types and Creator Codes on Mac OS X MCs smoke crack, I smoke aluminum! iTunes Shell Script

  5. The Lewis Butler script is not available at that URL any more. I made an addition to change the volume, add this in the case statement:

    vl)

    osascript \

    -e "tell application \"iTunes\"" \

    -e " set sound volume to $2 " \

    -e "end tell"

    ;;

    Then this to the help section:

    echo "itunes vl x : set volume to x where x is 0-100"


Comments RSS

Leave a Reply


Warning: Undefined variable $user_ID in /var/www/vhosts/nslog.com/httpsdocs/wp-content/themes/nslog/comments.php on line 96

Please abide by the comment policy. Valid HTML includes: <blockquote><p>, <em>, <strong>, <ul>, <ol>, and <a href>. Please use the "Quote Me" functionality to quote comments.