AppleScript щелкает каждый элемент с помощью сценариев графического интерфейса

Я хотел бы перебрать каждый элемент в окне iTunes и попытаться щелкнуть каждый элемент.

Я также хотел бы написать в текстовый файл, показывающий каждый элемент, который я щелкнул.

Код, который я написал ниже, не работает. В частности, я получаю сообщение об ошибке процесс «iTunes» не понимает сообщение click_an_element.

Мысли, что я делаю не так?

Спасибо!!

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

person user141146    schedule 14.06.2010    source источник


Ответы (1)


вы выходите за рамки, он думает, что click_an_element - это функция iTunes

вам нужно добавить «мой» к этому вызову

Редактировать: поскольку у меня было некоторое время за обедом, я немного поиграл с этим, пришлось отключить нажатие, потому что оно щелкало кнопкой свертывания, а затем не давало доступ к другим элементам.

  tell application "iTunes" to activate
  tell application "System Events"
    tell process "iTunes"
        set elements to get entire contents of window "iTunes"
    end tell
    repeat with i from 1 to (length of elements)
        set ele to item i of elements
        --my click_an_element(ele)
        my show_what_you_clicked(description of ele)
    end repeat
  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
person mcgrailm    schedule 14.06.2010