2010-06-14 55 views
0

我想遍歷iTunes窗口上的每個元素並嘗試點擊每個元素。applescript通過gui腳本點擊每個元素

我也想寫一個文本文件來顯示我點擊過的每個元素。

我在下面寫的代碼不起作用。具體來說,我得到錯誤過程「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 

回答

0

你的範圍了它認爲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 
+0

omfg謝謝.. ..! – user141146 2010-06-14 17:52:05

+0

@ user141146很高興我可以幫助不知道爲什麼你想做這樣的事情.... – mcgrailm 2010-06-14 20:43:56