яблочный скрипт щелкнуть по каждому элементу через графический интерфейс - PullRequest
0 голосов
/ 14 июня 2010

Я бы хотел пройтись по каждому элементу в окне 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

1 Ответ

1 голос
/ 14 июня 2010

вне вашей области видимости, что click_an_element - это функция itunes

вам нужно добавить "my" к этому вызову

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

  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
...