duplicating to a new iTunes playlist

Hey,
I was wondering if anyone knew how to do this:
I am currently trying to make a program that creates a new playlist and duplicates a song automatically by finding its name. I know how to do everything except make it duplicate the song to the new playlist by finding it by name. I know there’s a way to do it by selecting it and saving the selection’s item 1, but i was wondering if there was a way to do it without the user selecting the song and highlighting it.
If I’m not being clear enough let me know.
Thanks for any help

Hi,

Here’s an example:

tell application "iTunes"
	activate
	set lib_pl to first library playlist
	-- just getting a track name
	set track_name to name of some track of lib_pl
	--
	-- get an alias reference to the first track with that name
	-- note that you may have more than one track with that name
	set track_loc to location of first track of lib_pl whose name is track_name
	-- make a playlist
	set new_playlist to (make new playlist with properties {name:"My New Playlist"})
	-- add the track to the new playlist
	set added_track to (add track_loc to new_playlist)
	-- if you want to see the song playing
	set view of first browser window to new_playlist
	play added_track
end tell

gl,

Thanks a lot!
I’ll try that now.

Works great.
Thanks a lot Kel!

You’re welcome.

Glad it worked.

gl,