iTunes add album/artist to playlist.

Hi,

This is probably an easy one but I’m new to applescript so bare with me!

I’m writing a few scripts for iTunes that basically add selected songs to a certain playlist, plays the playlist etc.

They work fine but the problem is if I select an artist or album in the browser and run my script it adds noting to the playlist (It doesn’t recognise anything as being selected), but it does work if i select a song or group of songs.

Is there a way of knowing if an artist or album has been selected in the browser?

I want something like:

if (album/artist selected with no songs)
Loop to each song for the artist/album
add song to playlist

Thanks

I don’t think so; iTunes selection property will return an empty list.

You know the area of the front screen that shows the list of songs for the artist/album combination selected?

Is there a property that stores that list of songs? That would work either

Sorry, I don’t have time to work on a full solution, but perhaps this is a start.
If you have an artist selected in iTunes, then the following script will create a new selection based on that artist / album.
(All you need to do now is fill a new playlist with this selection!..)
Is that what you were wanting to do?

tell application "iTunes" to activate
tell application "System Events" to tell process "iTunes"
	keystroke "f" using {command down, option down} -- This whole series of convoluted keystrokes is just to ensure that the leftmost column is active.
	delay 0.2
	keystroke tab & tab
	delay 0.2
	keystroke "a" using {command down}
end tell
tell application "iTunes" to set s to selection
return s

PJ.

Ah I get ya, basically what that’s donig is selecting all the songs (Cmd+A)? Yeah that should work I’ll give it a try later on

Thanks

I’ve tried that and it does select the tracks (It needs 3 tabs rather than two by the way)

However when I try to add the tracks to the playlist as i did before the selection seems to be empty.

For some reason when i select all tracks manually it works ok but if i try selecting all tracks in the script it doesn’t work!!

Anyone have any ideas?

Model: PowerMac G5
Browser: Firefox 1.5.0.4
Operating System: Mac OS X (10.4)

This script does the whole job on my system. Let me know what error message it gives you.

tell application "iTunes" to activate
tell application "System Events" to tell process "iTunes"
	keystroke "f" using {command down, option down} -- This whole series of convoluted keystrokes is just to ensure that the leftmost column is active.
	delay 0.2
	keystroke tab & tab -- You can add "& tab" if you need to, but 3 tabs doesn't work on my system
	delay 0.2
	keystroke "a" using {command down}
end tell
tell application "iTunes"
	set s to selection
	repeat with ThisSong in s
		add (get location of ThisSong) to playlist "MyNewList"
	end repeat
end tell

I’ve tried that exact code (Except I put in 3 tabs and my own playlist name) and still no luck.

The reason is that selection is empty. The code never enters the loop at the end. It doesn’t throw any error messages
]It selects all of the tracks alright.

It’s a bit weird how come it works on yours but not mine?!!!