rmgirardin
rmgirardin

Reputation: 63

How do I add song to iTunes' "Up Next" with Applescript

I'm pretty new to Applescript (literally just started today), but I can not find out how to just play an album without having to create a playlist with only one album and play that playlist. Essentially I've figured out how to search for what I want and play something, but I can only play one song at a time.

tell application "iTunes"
    set search_results to (search playlist "Library" for "Monument Valley (Original Soundtrack)")
    repeat with i in search_results
        play i
    end repeat
end tell

If I do this, it runs through every song until it hits the last one and the last one is played. I believe you can use next track in order to add something to the "Up Next", but I haven't gotten it to work. Is there a way to actually do this or do I have to succumb to playing a playlist?

Upvotes: 4

Views: 1112

Answers (2)

Michael Simons
Michael Simons

Reputation: 4890

In case someone happens to end up here after like 7 years, I used a combination of AppleScript and Shortcuts to solve this:

https://github.com/michael-simons/scrobbles4j/commit/95244b20117e068c5e8fea331e0febb6b0ea2544

Upvotes: 1

anon
anon

Reputation: 154

Sadly, the iTunes AppleScript dictionary has no "terminology" for the Up Next queue. Even Doug's AppleScripts for iTunes, the iTunes scripting authority, has no scripts for Up Next. The next track command is just to "advance to the next track in the current playlist"— equivalent to pressing the "next" button. It seems the only way to script Up Next would be to use GUI scripting, meaning you would tell AppleScript which buttons in the Graphical User Interface to click instead of using an API. This can be quite difficult, so I think you'll have better luck if you just succumb to using playlists. Fortunately, the iTunes dictionary does include plenty of controls for creating and manipulating playlists.

Upvotes: 2

Related Questions