playing a certain part in a track and loop it.

I’m trying to create a little Applescript (which will eventually turn into a AS Studio app.) What I am trying to accomplish is to set a start time for a song and when i want it to stop and repeat. So the whole idea is to constanly repeat a ceratain part of a song until you get sick of it:P Just wondering how I would start it off.

Hendo:

This may help get you started:

tell application "iTunes"
	set a to item 1 of selection of front window --Even if you only select one track, your result is is list.
	set b to text returned of (display dialog "You have selected " & a's name & " by " & a's artist & ".  This track is " & a's duration & " seconds long.  Please enter a number less than " & (a's duration) - 20 & " as a start time." default answer 10)
	set a's start to (b as number)
	repeat
		back track --Essentially rewinds the track to the new start time
		play a
		delay 15 --Gives you a 15 second play 
		back track --Then rewinds again for the next play
	end repeat
end tell

There are two problems with this script as it stands. Number one, of course, is that there is no way to exit the repeat as written. Even if you stop the track in iTunes, this baby will continue on until you stop the script. Number two is that the selected track’s start time is never changed back to zero.

I believe that this is the only way to set a stop part of a track in iTunes. You can set a start time quite easily, but there is no stop that I can locate in the dictionary. Additionally, you need to stay away from the last 5 seconds of any track, since it is within that window that will trigger iTunes to go to the next track in the playlist. If you just want one track over and over, you need to either put it into a playlist of one track (and have your Preferences set to replay), or do something like this loop.

Good luck,

I just did this for stopping it at a certain point and looping (it’s not super smooth but hey…)

tell application "iTunes"
	set a to item 1 of selection of front window --Even if you only select one track, your result is is list.
	set b to text returned of (display dialog "You have selected " & a's name & " by " & a's artist & ".  This track is " & a's duration & " seconds long.  Please enter a number less than " & (a's duration) - 20 & " as a start time." default answer 10)
	set c to text returned of (display dialog "how long until repeating?" default answer "") as integer--how long to play until lopping
	set a's start to (b as number)
	repeat
		back track --Essentially rewinds the track to the new start time
		play a
		delay c --plays number of seconds specified above and then repeats.
		back track --Then rewinds again for the next play
	end repeat
end tell

Seems to work alright…not perfect by any means:P