iTunes 10.6.3 changes AppleScript interface?

2019-04-12 12:14发布

I have a simple Ruby script that uses the rb-appscript gem to control iTunes, and now that I've updated to iTunes 10.6.3, it appears to be broken.

Prior to 10.6.3, this piece of code would work as expected to get the currently selected track(s):

Appscript.app('iTunes').selection.get()

Now it produces the following error:

RuntimeError: Unknown property, element or command: 'selection'

Edit: Just confirmed that this is also broken in py-appscript, so it's not isolated to rb-appscript.

Which is weird, because the following piece of actual AppleScript still works:

tell application "iTunes" to get selection

Similar examples such as Appscript.app('Finder').desktop.files.get() still work.

I couldn't find any information that would explain if or why this was changed or what I could do to update my script. I'm guessing it has something to do with Mountain Lion changes.

3条回答
smile是对你的礼貌
2楼-- · 2019-04-12 12:41

Yeah, they definitely broke it. You COULD use rb-appscript with the System Events application to conditionally check the children of various UI elements to see if the 'selected' attribute is true.... e.g.:

i = 0
row_exists = true
selected_row = nil
while row_exists && !selected_row
    i += 1
    row_exists = app("System Events").application_processes["iTunes"].windows["iTunes"].scroll_areas[3].outlines[1].rows[i].exists
    if row_exists 
        if (app("System Events").application_processes["iTunes"].windows["iTunes"].scroll_areas[3].outlines[1].rows[i].attributes["AXSelected"].value.get == true)
            selected_row = app("System Events").application_processes["iTunes"].windows["iTunes"].scroll_areas[3].outlines[1].rows[i]
        end
    end 
end

You could then pull out required information from the children of the selected row. This is would be a pretty annoying way to go about this, though.

查看更多
We Are One
3楼-- · 2019-04-12 12:42

Looks like iTunes 10.6.3 was release with the sandboxing that is coming with Mountain Lion. Here is an article talking about it (read the comments, too) http://www.leancrew.com/all-this/2012/06/the-first-nail-in-the-coffin-of-python-appscript/

Probably will start happening much more (if not with everything) as of Mountain Lion

查看更多
贪生不怕死
4楼-- · 2019-04-12 12:56
登录 后发表回答