Search code examples
user-interfacescriptingwindowapplescriptitunes

Unnamed Window in Applescript


I'm scripting iTunes with applescript using UI scripting. Depending on what I'm doing an iTunes notification will appear, at which point I need to handle it. The name of the window is AXWindow: "", and I can't seam to get applescript to handle it. I've tried using the literal "", I've tried defining a variable to "", I've tried both cases with escape characters, and I've tried getting the name of the frontmost process.

tell application "System Events"
     set processName to name of front window
end tell
tell button "whatever" of window processName
     click
end tell

But that comes up with "error "System Events got an error: Can't get window 1. Invalid Index."" Any help on this would be greatly appreciated.


Solution

  • You can do something like this:

    tell application "iTunes" to activate
    tell application "System Events"
        tell process "iTunes"
            set xxx to first UI element whose role description is "dialog"
        end tell
    end tell
    

    Or to find them all:

    tell application "iTunes" to activate
    tell application "System Events"
        tell process "iTunes"
            set xxx to every UI element
        end tell
    end tell