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

Temporarily play an excerpt of an iTunes song Apps
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.
    •    
  • Currently 2.50 / 5
  You rated: 2 / 5 (4 votes cast)
 
[9,009 views]  

Temporarily play an excerpt of an iTunes song | 23 comments | Create New Account
Click here to return to the 'Temporarily play an excerpt of an iTunes song' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Temporarily play an excerpt of an iTunes song
Authored by: mattonmac on Mar 15, '07 08:34:28AM

I like it!



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: spstanley on Mar 15, '07 09:00:27AM

I've been thinking of good ways to come up with an iTunes-powered doorbell. This could help!



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: jvr on Mar 15, '07 11:07:48AM

Great idea! I've assigned a Quicksilver keyboard trigger to this script, and it works like a charm.



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: jwdunn on Mar 15, '07 12:27:54PM

Awesome! I'm always kind of sad when I have to abandon a currently playing song to sample something I just added to my library...problem solved!



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: voiceofra on Mar 15, '07 01:39:47PM

This rocks on so many levels.
Awesome \m/



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: jer2665 on Mar 15, '07 02:07:31PM

Ok, not sure what I'm doing wrong, but for some reason when I try to run ANY script from my itunes script folder, it's asking me for internet explorer app.

some i've downloaded like a randomize playlist thing work fine, but i just tried one of the older "cddb search this artist" and it asks for ie. i don't remember where I got those ones. But when I copied this script into script editor, it would give me an "application not open" error, same with when I typed it in. iTunes was open.

Any ideas?



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: MatMac on Mar 15, '07 05:14:52PM

I don't haveany script folder in my $HOME/Library/itunes...

Could somebody explain me Y ?

ThankZ
MAt



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: voiceofra on Mar 15, '07 06:14:05PM

$home/library/scripts/applications/itunes



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: mwncimelyn on Mar 16, '07 08:28:29AM

You can make a new folder there called Scripts and drop it into that.



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: jer2665 on Mar 15, '07 07:05:54PM

no idea what I did, I went through and deleted all the scripts that asked for ie or something, but I retried and it works fine now, and it's great. made a quicksilver trigger too, and it'll really help me making certain playlists. thanks



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: type88 on Mar 15, '07 06:59:27PM

Just what I always wanted!

What would make it even better would be if the "STOP" dialog could have a mechanism to rate the song you are playing an excerpt from. I do my best to stay on top of rating my songs and this would be a tremendous help. Is it doable?



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: Unsoluble on Mar 15, '07 09:55:15PM
This isn't exactly the solution you were thinking of, but you might want to try out Synergy. It lets you set up global keyboard commands for iTunes. I use it to change star ratings for the currently playing song even when I'm in another app -- I'm using Control-Up Arrow and Down Arrow, which are pretty convenient.

[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: mwncimelyn on Mar 16, '07 08:21:29AM

This script should do it.

tell application "iTunes"
set currentTrack to current track
set playPosition to player position
set theSampleTrack to selection
play selection
set player position to 50
set theRating to (choose from list {1, 2, 3, 4, 5} with prompt "Please set your rating then click OK" without multiple selections allowed) as integer
set theSampleTrack to current track
if theRating is not false then set the rating of theSampleTrack to theRating * 20
play currentTrack
set player position to playPosition
end tell

I've changed my script to this now - thanks for the tip.



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: mark hunte on Mar 16, '07 09:17:01AM
The new script works well. Can I suggest you add 0 to the ratings. And a default :
set theRating to (choose from list {0, 1, 2, 3, 4, 5} with prompt "Please set your rating then click OK" default items "0" without multiple selections allowed) as integer

---
mh

[ Reply to This | # ]

Temporarily play an excerpt of an iTunes song
Authored by: mark hunte on Mar 16, '07 11:24:10AM
Actually this works a little better. The default will be what Ever the current rating is for the sample track.
So if the sample has no rating then the default selection will be 0
If its 3 the default will be 3.
tell application "iTunes"
	set currentTrack to current track
	set playPosition to player position
	set theSampleTrack to selection
	play selection
	set player position to 50
	set R to (rating of current track) / 20 as integer
	set theRating to (choose from list {0, 1, 2, 3, 4, 5} with prompt "Please set your rating then click OK" default items R without multiple selections allowed) as integer
	set theSampleTrack to current track
	if theRating is not false then set the rating of theSampleTrack to theRating * 20
	play currentTrack
	set player position to playPosition
end tell 

---
mh

[ Reply to This | # ]

Temporarily play an excerpt of an iTunes song
Authored by: type88 on Mar 16, '07 11:39:54AM

Works a dream. Thank you.



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: lemac on Mar 16, '07 09:02:28AM
Doesn't work for me.

I get this AppleScript Error: "Unknown object type."

If I run the script from the Apple Script Editor, the second "current track" on the second line gets highlighted.

Any thought?

[ Reply to This | # ]

Temporarily play an excerpt of an iTunes song
Authored by: mark hunte on Mar 16, '07 11:52:51AM

You have to be playing a track first.
The object you are not getting is the current track that should be playing

---
mh



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: TheCrunge on Mar 16, '07 09:58:20AM
I like this hint. I added a little more functionality. This allows you to revert (as the original script does), continue to play the selected track, or play the selected track from the beginning. In case you sample the tune and would like to let it play on, or would like to hear it from the beginning:
tell application "iTunes"
	set answer1 to "Revert"
	set answer2 to "Let This Play"
	set answer3 to "Play This From Beginning"
	set playerOffset to 50 --seconds
	
	set currentTrack to current track
	set playPosition to player position
	set theSampleTrack to selection
	
	play selection
	set player position to playerOffset
	
	set theChoice to (display dialog "Sampling Track..." buttons {answer2, answer3, answer1} default button 3)
	if button returned of theChoice is answer1 then
		play currentTrack
		set player position to playPosition
	else if button returned of theChoice is answer2 then
		return
	else if button returned of theChoice is answer3 then
		set player position to 0
	end if
end tell


[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: digitol on Mar 16, '07 05:46:11PM

mwncimelyn:

THANKS FOR THIS! EXCELLENT Little scripting there! A++++!! Anyone know how to adapt this to make it export the first whatever seconds of the song? would be AWESOME to build a previews list or library.



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: drudus on Mar 16, '07 07:32:43PM
Great idea. I added an extra if clause to TheCrunge's script to check if a track is playing...

tell application "iTunes" if player state is equal to playing then set answer1 to "Revert" set answer2 to "Let This Play" set answer3 to "Play This From Beginning" set playerOffset to 50 --seconds set currentTrack to current track set playPosition to player position set theSampleTrack to selection play selection set player position to playerOffset set theChoice to (display dialog "Sampling Track..." buttons {answer2, answer3, answer1} default button 3) if button returned of theChoice is answer1 then play currentTrack set player position to playPosition else if button returned of theChoice is answer2 then return else if button returned of theChoice is answer3 then set player position to 0 end if end if end tell

You can also set a shortcut to Apple Scripts installed in an application by entering the script name in the keyboard shortcuts in the System Preferences. Good work.

[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: richorlin on Mar 19, '07 10:48:02AM

You can combine sampling a track, rating it and continuing play or revert to original track with this script:

tell application "iTunes"
set answer1 to "Revert"
set answer2 to "Let This Play"
set answer3 to "Play This From Beginning"
set playerOffset to 10 --seconds

set currentTrack to current track
set playPosition to player position
set theSampleTrack to selection

play selection
set player position to playerOffset
set R to (rating of current track) / 20 as integer
set theRating to (choose from list {0, 1, 2, 3, 4, 5} with prompt "Please set your rating then click OK" default items R without multiple selections allowed) as integer
set theSampleTrack to current track
if theRating is not false then set the rating of theSampleTrack to theRating * 20
set theChoice to (display dialog "Sampling Track..." buttons {answer2, answer3, answer1} default button 3)
if button returned of theChoice is answer1 then
play currentTrack
set player position to playPosition
else if button returned of theChoice is answer2 then
return
else if button returned of theChoice is answer3 then
set player position to 0
end if
end tell



[ Reply to This | # ]
Temporarily play an excerpt of an iTunes song
Authored by: activa on May 17, '07 10:09:31AM

<RANT>
Only very slightly OT:

Um... why isn't this rather obvious feature already included? I can't remember the number of times I've wanted to just preview, say, the first 5 seconds of the songs on a CD or playlist. For that matter, why isn't iTunes skinnable, and why won't it export MP3? I know it's a great program and it's free, but as it's basically a font-end to a store, seems like Apple should make it a little more flexible for users.
</RANT>



[ Reply to This | # ]