Is there a simple way to play an album/ar…
apple Verified ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
There's a lot to be found online about everything re: iTunes and AppleScript -- simple ways to play a playlist, play a stream, bump to previous/next track, set volume, etc. But for whatever reason, playing an album or artist has to be much more complicated, and I've found almost no advice about it.
Indirectly I've seen part of a solution to, for example, "set my
tracklist to (every track of playlist 'Library' whose artist is '$artist' ...)" etc. Then I assume you must loop through and play each track.
Is there no way to do this more simply, without all the jumping jacks -- in other words can't I just tell iTunes (in AppleScript, from the shell w/osascript) to select and play an album or artist?
I probably could have gone farther with this if I had found a reference somewhere that says, "Here's what you can do with iTunes and AppleScript," but I can't find that either.
11 replies
Sign in or join Beachball Help to reply.
- 0
Camelot ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
>Indirectly I've seen part of a solution to, for example, "set mytracklist to (every track of playlist 'Library' whose artist is '$artist' ...)" etc. Then I assume you must loop through and play each track.
No, you don't need to loop through the list. You can play them directly:
<pre class=command>tell application "iTunes"
play (every track of playlist "Library" whose album is "Shine")
end tell</pre>or, via the shell:
<pre class=command>osascript -e 'tell application "iTunes" to play (every track of playlist "Library" whose album is "Shine")'</pre>
- 0
jccc ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
It didn't like the escaped quotes. It did work without the escaped quotes, however only the first found track played, followed by some random track elsewhere in the library. Response on the command line was:
<pre class=command> > osascript -e 'tell application "iTunes" to play (every track of playlist "Library" whose artist is "The Beatles")'
iTunes, iTunes, iTunes, iTunes, iTunes, iTunes, iTunes, iTunes, iTunes</pre>That's one "iTunes" for each matching track it found. But after the first track, some non-matching track from the rest of the library plays.
- 0
jccc ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Interesting ...
Playing just one track ("whose name is ...") finds and plays the song, then continues playing some random track from the library rather than stopping. That doesn't seem right either.
- 0
Camelot ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Do you have shuffle turned on? It may be that shuffle is overriding the list of songs to play.
- 0
Bill Scott ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
open foo.mp3
(Har har).
- 0
jccc ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Do you have shuffle turned on? It may be that shuffle
is overriding the list of songs to play.Shuffle indeed was/is not on.
Does the above osascript line work for you -- i.e. playing an artist/album and correctly playing beyond the first track? If so, then I definitely have something strange happening on my end.
- 0
casdvm ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
This works on my machine:
osascript -e 'tell application "iTunes" to play track 1 of playlist "Cubs"'
By telling iTunes to play track 1 of a playlist, it will make that playlist the 'active' playlist, and it will continue to play all the tracks in that playlist (shuffle or not) until it is finished.
- 0
jccc ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I assumed that would work for a named, pre-existing playlist, and your line does. But what I'm trying to do still doesn't work that way, behaving the same as described above (playing one found track, then going off to other random tracks):
osascript -e 'tell application "iTunes" to play track 1 of (every track of playlist "Library" whose artist is "The Beatles")'
This appears to be the only way it will work:
osascript -e 'tell application "iTunes"' -e 'if (exists playlist "temp_playlist") then' -e 'delete playlist "temp_playlist"' -e 'end if' -e 'set name of (make new playlist) to "temp_playlist"' -e 'set theseTracks to every track of playlist "Library" whose artist is "The Beatles"' -e 'repeat with thisTrack in theseTracks' -e 'duplicate thisTrack to playlist "temp_playlist"' -e 'end repeat' -e 'play playlist "temp_playlist"' -e 'end tell'
Which is fine by me I suppose. Can wrap it up into it's own script or shell script. I just wish the actual AppleScript were more graceful for doing something this straightforward.
- 0
jccc ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Best I've come up with below. I put this into /usr/local/bin as "playitunes" (remembering to chmod 755) for a case-insensitive search of all artists, albums and track names. I'm sure there's a more graceful way to do this, and I have no idea how to set the sort order, but it works.
----------------------------------
#!/bin/bash
osascript -e 'tell application "iTunes"' -e 'if (exists playlist "temp_playlist") then' -e 'delete playlist "temp_playlist"' -e 'end if' -e 'set name of (make new playlist) to "temp_playlist"' -e 'set theseTracks to every track of playlist "Library" whose artist contains "'"$1"'"' -e 'repeat with thisTrack in theseTracks' -e 'duplicate thisTrack to playlist "temp_playlist"' -e 'end repeat' -e 'set theseTracks to every track of playlist "Library" whose album contains "'"$1"'"' -e 'repeat with thisTrack in theseTracks' -e 'duplicate thisTrack to playlist "temp_playlist"' -e 'end repeat' -e 'set theseTracks to every track of playlist "Library" whose name contains "'"$1"'"' -e 'repeat with thisTrack in theseTracks' -e 'duplicate thisTrack to playlist "temp_playlist"' -e 'end repeat' -e 'play playlist "temp_playlist"' -e 'end tell'
----------------------
Sorry, I can't get line breaks to work in here at all, so the above is just ugly.
- 0
jccc ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Okay, well after a while this starts happening:
MY PROMPT: osascript -e 'tell application "iTunes" to play playlist "Radio"'
THE RESPONSE: 2007-07-26 03:50:12.127 osascript(778) CFLog (0): CFMessagePort: bootstrap_register(): failed 1100 (0x44c), port = 0x2103, name = 'Processes-0.17301505'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2007-07-26 03:50:12.128 osascript(778) CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (Processes-0.17301505)
CFMessagePortCreateLocal failed (name = Processes-0.17301505 error = 0)
Abort trapThe actual Applescript being sent to iTunes doesn't matter. My first osascript attempts after a fresh boot work over and over. After iTunes has been playing a while, this starts failing with the above message.
Actually, I just checked and any attempt to invoke osascript for anything gives me the same error. I don't know if this has something to do with using the script I cobbled together (previous message above), but I think I've pretty much given up on this. I can't even get this forum text box to take the error message text correctly without munging it with its "helpful" edits.
- 0
foilpan ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
i haven't tried this yet to see if it will work as you want, but i know it does play audio via the command line. it looks like it can interpret playlists and artist or album directories, too.