PDA

View Full Version : Looking for a Script to Play First 10 Songs of Playlist


iTunesFMPGuy
07-18-2003, 10:49 AM
Hi there,

I use FileMaker Pro as a software jukebox. Using AppleScript I transfer a found set of songs from FileMaker to make a playlist in iTunes. Often the found set is large, over 100 or even 200 songs.

Does someone know of an AppleScript that will play the first 10 songs of a playlist or could a good AppleScripter help me modify my existing AppleScript to pick the first 10 songs of a found set?

Here's how my AppleScript works:

In FileMaker I get a list of songs from a found set. The list is set to "thisSong". Then I tell iTunes to set the tracks to "thisSong":

tell application "iTunes"
set new_playlist to make new playlist
set the name of new_playlist to "Now Playing"
set shuffle of new_playlist to false
set theTracks to thisSong
add theTracks to new_playlist
set the view of the front browser window to playlist "Now Playing"
play new_playlist
end tell

Doug Adams
07-18-2003, 03:08 PM
There isn't really an efficient way to play a "list" of tracks. I suppose you could have a stay-open script with an idle handler keep count of how many tracks have played, but the best this could do is stop the eleventh one after it started.

You could create another ten-track playlist, and destroy it later:

tell application "iTunes"
set new_playlist to make new playlist
set the name of new_playlist to "Now Playing"
set shuffle of new_playlist to false
set theTracks to thisSong
add theTracks to new_playlist
set the view of the front browser window to playlist "Now Playing"

set thisP to (get view of front window)
set thatP to (make new playlist with properties {name:"10 songs"})
tell thisP
repeat with t from 1 to 10
try
duplicate track t to thatP
end try
end repeat
end tell
play thatP
end tell


Or something like that :)

You may be tempted to put a "delete thatP" as a final routine, but again, this requires "watching" the playlist from a stay-open/idle handler script.

iTunesFMPGuy
07-18-2003, 03:23 PM
Thanks Doug. I appreciate your reply.

Doug Adams
07-18-2003, 03:39 PM
Here's a sort of stay-open idle handlin' thing:

property theT : ""
property counter : 0
on run
set counter to 0
tell application "iTunes"
play
try
if player state is playing then
set theT to current track
end if
end try
end tell
end run

on idle
tell application "iTunes"
try
if player state is playing then
set theC to current track
if theC is not theT then
set counter to counter + 1
copy theC to theT
end if
if counter is 11 then
stop
tell me to quit
end if
end if
end try
end tell
return 10 -- check every 10 seconds
end idle

Save as application, with stay open. It will play ten tracks and stop at the 11th.