Teo Choong Ping
Teo Choong Ping

Reputation: 12798

How to detect window index of firefox?

I'm trying to get the window index (position) firefox on desktop with Applescript. I got to this far but I don't know how to proceed. Can somebody point to me some example code or clue. :-|

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

Upvotes: 0

Views: 271

Answers (1)

regulus6633
regulus6633

Reputation: 19030

You have to know some property of the window you want to identify. In my example I assume you know the name of the window.

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

Upvotes: 1

Related Questions