Use iTunes' Up Next function with an API

Solutions Collect From Internet About “Use iTunes' Up Next function with an API”

iTunes has no public API but the scripting bridge

you could use Applesript UI Scripting I’d wager — but that would be very fragile

you can also simulate a keypress then:
That less fragile than scripting the visible interface (IMO):
http://hints.macworld.com/article.php?story=20121203223100335

TADA — YAY — a ‘ready’ script that will add songs selected to UpNext ::

tell application "AppleScript Utility"
    set GUI Scripting enabled to true
end tell

tell application "iTunes"
    --get the song
    set l to playlist "Purchased"
    set t to item 5 of tracks of l

    --focus it in list
    reveal t

    --show window
    activate
end tell

tell application "System Events"
    -- option enter
    delay 1
    key down option
    delay 1
    key code 36
    key up option

    -- Click the “Play Song” button in the annoying dialog.
    set w to null
    try
        set w to window "Add to Up Next" of application process "iTunes"
    end try
    if w is not null then
        set b to UI element "Play Song" of w
        click b
    end if
end tell