2011-05-24 35 views
0

我試圖在桌面上用AppleScript獲取窗口索引(位置)firefox。 我已經走到了這麼遠,但我不知道如何繼續。有人可以給我一些示例代碼或線索。 : - |如何檢測firefox的窗口索引?

tell application "System Events" 
    set programs to processes whose visible is true and name is "firefox-bin" or name is "google chrome" or name is "safari" 

    repeat with program in programs 
     tell window of application program 
      #XXX do something 
     end tell 
    end repeat 
end tell 

回答

1

您必須知道要識別的窗口的某些屬性。在我的例子中,我假設你知道窗口的名字。

set windowName to "some name" 
set windowIndex to missing value 

tell application "System Events" 
    set programs to processes whose visible is true and name is "firefox-bin" or name is "google chrome" or name is "safari" 

    repeat with program in programs 
     tell program 
      set windowNames to name of windows 
      repeat with i from 1 to count of windowNames 
       if windowName is item i of windowNames then 
        set windowIndex to i 
        exit repeat 
       end if 
      end repeat 
     end tell 
    end repeat 
end tell 

return windowIndex