applescript click every element via gui scripting

Posted by user141146 on Stack Overflow See other posts from Stack Overflow or by user141146
Published on 2010-06-14T15:19:07Z Indexed on 2010/06/14 15:22 UTC
Read the original article Hit count: 207

Filed under:
|

Hi, I'd like to iterate through every element on an iTunes window and try to click on each element.

I'd also like to write to a text file showing each element that I've clicked.

The code that I wrote below isn't working. Specifically, I get the error process "iTunes" doesn’t understand the click_an_element message.

Thoughts on what I'm doing wrong?

Thanks!!

tell application "iTunes" to activate
tell application "System Events"
    tell process "iTunes"

        set elements to get entire contents of window "iTunes"
        repeat with i from 1 to (length of elements)
            set ele to item i of elements
            click_an_element(ele)
            show_what_you_clicked(ele)
        end repeat
    end tell
end tell


-------handlers------------
to click_an_element(an_element)
    tell application "iTunes" to activate
    tell application "System Events"
        tell process "iTunes"
            try
                click an_element
            end try
        end tell
    end tell
end click_an_element

to show_what_you_clicked(thing_to_type)
    tell application "TextEdit" to activate
    tell application "System Events"
        tell process "TextEdit"
            keystroke thing_to_type
            key code 36
        end tell
    end tell
end show_what_you_clicked

© Stack Overflow or respective owner

Related posts about applescript

Related posts about handler