Hello,
I am having some difficulty in creating an AppleScript that can copy a selected list of songs from the iTunes Store to a playlist (for future publishing as an iMix).
Here is the rough start I have developed so far:
set myPlaylist to "My iMix"
tell application "System Events" to tell process "iTunes"
set thePlaylist to every row of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 whose value of static text 1 is myPlaylist
tell window "iTunes" to tell outline 1 of (get 1st scroll area of splitter group 1 whose static texts of outline 1 is {})
set theSongList to every row
repeat with theSong in theSongList
copy theSong to thePlaylist
end repeat
end tell
end tell
Pieces of the code work, but I have yet to figure out how to copy the song to the playlist.
Any comments or suggestions are greatly appreciated.
First off, you needn’t use System Events for this. You can talk directly to iTunes to do what you want to do. In fact, as you’ve written:
tell application "System Events" to tell process "iTunes"
You’ve not told iTunes anything. With tell, you use one of two formats:
Tell application "System Events" to tell process "iTunes" to set isFront to frontmost --just an example
or
tell application "System Events"
tell process "iTunes"
set isFront to frontmost --just an example
end tell
end tell
You also don’t need to ask all the row/scroll/splitter stuff. Go take a look at iTunes’ dictionary, you can just say:
tell application "iTunes"
set the songList to every track of playlist "myPlaylist"
end tell
Thanks for your reply.
What you are suggesting works when accessing local files. However, when trying to add (non-purchased) items from the iTunes Store to a playlist, your proposed solution does not work.
It seems as though iTunes Store scripting is not very easy to do.
Yes, I see your point. Not sure it will let you add items that are not from the Store. I just tried to make one with stuff that WAS from the store and it only took 3 of them, oddly enough. Strange…
Would you mind sharing the AppleScript code you wrote? Every little idea helps at this point. 
Sadly, there isn’t any code. I was just creating an iMix from a playlist I already have (made up, I might add, with iTunes’ own FREE SINGLES) and it would only take 3 of them! :rolleyes:
Ok, thanks anyway.
Are you familiar enough with the UI Scripting of AppleScript to add a song (from the iTunes Store browser) to a playlist?
That part alone would be a fantastic start.
I’ve done some AS Studio stuff, which is all UI scripting, so I’ll give this a look and get back to ya!
I would have tried a click command to loop through the row outline for the ADD SONG button ,But it seems to only be listed as Text.
Clicking on the ADD button would result in either purchasing the song or adding the song to your shopping cart, which is not exactly what I am trying to accomplish.
I am trying to add the songs to a playlist, without purchasing them.
This can be done manually, by dragging the songs to a playlist, but I would like to automate this process with an AppleScript.
When you say
Which pieces do you mean?
I’ve been trying all afternoon and cannot get the UI Inspector and Script Editor to agree. UI Inspector says I’m in one place and SE says I’m not. I’m wondering if any of these controls are customized and therefore not accessible through ordinary means…
My apologies in advance for not including all of the code in my original post.
The following code will return a list of songs (titles) from the iTunes Store:
tell application "System Events" to tell process "iTunes"
tell window "iTunes" to tell outline 1 of (get 1st scroll area of splitter group 1 whose static texts of outline 1 is {})
set theSongList to value of text field 1 of every row
end tell
end tell
Is this helpful?
Can anyone share some ideas as to how I might accomplish the original requested task?