Temporarily play an excerpt of an iTunes song

Mar 15, '07 07:30:05AM

Contributed by: mwncimelyn

Today I was trying to organise my iTunes library, making playlists, rating songs, etc. As I do this, I usually like to listen to some music. As a playlist or Party Shuffle is playing in the background, I sometimes would like to play just a little bit of a song to remind myself of how it goes, to help decide how I'm going to rate it. However, this always means either stopping the song that's playing, or waiting until it ends and then possibly forgetting what I wanted to play a sample of in the first place.

So today I wrote the following AppleScript that I then placed in the iTunes script folder (~/Library » iTunes » Scripts), which makes it accessible from the script menu in iTunes:

tell application "iTunes"
  set currentTrack to current track
  set playPosition to player position
  set theSampleTrack to selection
  play selection
  set player position to 50
  display dialog "Sampling Track. Click Stop to revert to the previously playing track" buttons {"Stop"}
  if button returned of the result is "Stop" then
    play currentTrack
    set player position to playPosition
  end if
end tell

If I come across a song I'd like to hear a little bit of, I select my script from the menu (I've saved mine as Sample this song). It then starts to play the selected song and displays a dialog box with a stop button. When I have heard enough, I hit the stop button and the song that was previously playing begins again from the position at which I interrupted it.

In the script, I have included the line set player position to 50. This starts playing the selected song from 50 seconds in to avoid listening to lengthy intros. This can be amended or deleted if you'd prefer to sample the song from the beginning.

Comments (23)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070313124851912