iTunes "Up Next", again

Dear Lazyweb, the latest iTunes update broke my script that clicks this button:

tell application "System Events" to tell last splitter group of first window of application process "iTunes"
  click (first button whose description is "shuffle")
end tell

Either the button is no longer called "shuffle" or it's in a different place or something. I have no idea how to figure out what the names and hierarchy of these UI elements are. I don't even know how anyone figured that out last time. Do you?


Tags: , , , ,

11 Responses:

  1. Nate says:

    UI Browser is the most friendly version of this. It allows you to select an element, highlights it yellow, and prints out the AppleScript to use it. It works really well.

    • jwz says:

      Ok, I think this is working?

      tell application "System Events" to tell last group of last splitter group of first window of application process "iTunes"
        click (second button)
      end tell

      but it's some bullshit to refer to the thing as "second button" instead of by name. But maybe buttons are nameless now? Thanks, iTunes, you're so awesome you are literally giving me a brain tumor.

      • Nate says:

        I've noticed some of their elements move in and out of having a proper name. The closest guess I have is that it's something to do with the HTML element that they keep using. Things "inside" the HTML element are harder to target with AppleScript.

      • Jeff Clough says:

        It's inexcusable that an Official Apple Product does not give an AppleScriptable and discoverable name to each and every one of its buttons.

        This not being the case is one of the many little things which have kept AppleScript in a kind of uncanny valley for programming languages: so close to, and yet not, awesome that it ends up repulsing all who behold it.

        Then again, maybe I'm just drunk.

  2. James says:

    From that very previously.

    "Because Apple hates you, this will probably break with exciting unpredictable results someday. On that day, you should use the Accessibility Inspector tool (part of XCode) to inspect the new view hierarchy, and adjust the script to match."

  3. slick says:

    From what I'm seeing, that button merely executes these two menu commands in order:

    - Controls > Shuffle > On
    - Controls > Play

    After an incredible amount of trial and error (that involved voice-synthesized debug logging), I was able to write an AppleScript that clicks a menu item and plays a playlist:

    tell application "iTunes" to activate

    tell application "System Events" to tell process "iTunes" to click menu bar 1's menu bar item "Controls"'s menu 1's menu item "Shuffle"'s menu 1's menu item "On"

    tell application "iTunes" to play playlist named "Fun Times 1990"

    • Line Noise says:

      And I thought Java was verbose!

      Those possessive apostrophes after the quoted strings are doing my head in!

      • Leonardo Herrera says:

        I bet the guy who wrote those lexical analysis routines got a boner was extremely satisfied with himself when doing it.

    • phuzz says:

      That looks like pseudo code written by someone with a degree in English literature who was deliberately trying to obscure it's meaning.

      (the language in general, not your code slick)

      • Ian says:

        If it was, they could probably spell 'its' correctly.

        Apple: because its software never breaks.

  • Previously