Applescript - Get status of windows ( Visible or in the dock )

余生长醉 提交于 2019-12-11 09:17:46

问题


I need some help for my appleScript.

For all open windows, I want to know which one is hidden (in the dock), which one is visible and which one is focused?

To list windows I use :

tell application "System Events"
    set procs to processes
    set windowName to {}
    repeat with proc in procs
        try
            if exists (window 1 of proc) then
                repeat with w in windows of proc
                        copy w's name to the end of windowName
                end repeat
            end if
        end try -- ignore errors
    end repeat
end tell
return windowName

I tried focused property:

copy w's focused to the end of windowName

and selected property:

copy w's selected to the end of windowName

But this doesn't work!

Thanks for help!


回答1:


On Mac OS X 10.6 (AppleScript 2.1.2) the description property of a window of an application process (in System Events' terms) is "dialog" if the window is miniaturized (in the Dock), and some other value (such as "standard window", but can be something different depending on the application) if it's not miniaturized.

When an application is hidden altogether (using cmd+H or the "Hide" command from the application's menu), all of its windows will be hidden, regardless of whether they were miniaturized or not, so to find out whether it's hidden, use

visible of application process "<ProcessName>"

It's false when the application is hidden. To un-hide it, set that property to true.

To find out which window of an application is currently focused (frontmost/active), use

window 1 of application process "<ProcessName>"

The list of windows of an application (returned by windows of application process...) is ordered by the vertical stack: the frontmost window is first, the one behind it is second, and so on.

Since in OS X only one application is frontmost at a time, and only one window is in the foreground, you'll get at the currently focused window like this:

window 1 of (first application process whose frontmost is true) 


来源:https://stackoverflow.com/questions/10155694/applescript-get-status-of-windows-visible-or-in-the-dock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!