列出所有应用程序的所有窗口 [英] Listing all windows of all applications

查看:185
本文介绍了列出所有应用程序的所有窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个重新调整所有打开的窗口AppleScript脚本。为了确保我得到的所有窗户,我正在做我的脚本说,应用程序的名称,以及该应用程序的打开窗口的数量。结果
有趣的是,当我听到我的所有打开的应用程序的名称,我的脚本说,它们都具有0窗户打开。我怎样才能解决这个问题?

I am trying to write an applescript script that resizes all open windows. In order to make sure that I'm getting to all the windows, I'm making my script say the name of the application as well as the number of open windows of that application.
Interestingly, while I hear the names of all my open applications, my script says that they all have 0 windows open. How can I fix this issue?

下面是我的code:

tell application "System Events"
    repeat with theProcess in (every process)
        if background only of theProcess is false then
            if name of theProcess is not "Finder" then
                if name of theProcess is "Google Chrome" then
                    say "Chrome woo hoo"
                    say (count windows as string)
                else
                    say name of theProcess as string
                    say (count windows as string)
                    tell theProcess
                        repeat with theWindow in windows
                            say "found a window of"
                            say (name of theProcess) as string
                            tell theWindow
                                click button 2
                            end tell
                        end repeat
                    end tell
                end if
            end if
        end if
    end repeat
end tell

我在Mac OS X 10.7.5,采用2.2.4的Automator /写运行该AppleScript的

I'm on Mac OS X 10.7.5, using automator 2.2.4 to write/run this applescript

推荐答案

您必须告诉进程数窗口。毕竟这是它知道它的窗口,而不是系统事件的进程。

You have to tell the process to count windows. After all it's the process that knows about its windows, not system events.

您已经告诉进程例如说,它的名字说theProcess作为字符串名称,然而你只能用说(算Windows作为字符串)...没有任何进程绑定到了。尝试算theProcess的窗口。基本上,你有行的地方,有时你告诉这个过程中,其他时候,你不这样做,其他时候,你告诉这个过程,即使你已经告诉了过程,所以你做两次。这就是你有说的那样的字符串(theProcess名称),但code是在一个告诉theProcess块所以它已经被告知theProcess。

You have told the process to say its name e.g. "say name of theProcess as string" however you only use "say (count windows as string)"... no process is tied to that. Try "count windows of theProcess". Basically you have lines where sometimes you tell the process, other times you don't, and other times where you tell the process even though you've already told the process, so you do it twice. That's where you have "say (name of theProcess) as string" but that code is inside a "tell theProcess" block so it's already being told to theProcess.

真的是你需要通过你的code和更precise。小费......如果你想点击一个窗口,那么窗口必须在屏幕上最前面的一个按钮,否则你不能点击它。另一个技巧......名已经是一个字符串,所以你不必强迫,为一个字符串。

Really you need to go through your code and be more precise. A tip... if you want to click a button in a window then the window must be frontmost on the screen otherwise you can't click it. Another tip... "name" is already a string so you don't need to coerce that to a string.

顺便说一句,我与迈克尔Dautermann的到您的文章评论同意...会有过程,你不会得到访问。但是你会发现,从你的进步。

By the way, I agree with Michael Dautermann's comment to your post... there will be processes where you won't get access. But you'll find that out as you progress.

下面是我会怎么写你的code。基本上,我会得到所有的变量在使用讲theProcess块的开始。然后,我可以做的东西与这些变量。我希望帮助。请注意,我只发过程中最前面的,这意味着如果它有多个窗口打开它只会点击前窗上的一个按钮。你必须加code键使每个窗口前面来之前,你可以点击相应的按钮。祝你好运。

Here's how I would write your code. Basically I would get all of the variables at the beginning using a "tell theProcess" block. Then I can do stuff with those variables. I hope that helps. Notice that I only made the process frontmost which means if it has multiple windows open it will only click a button on the front window. You'll have to add code to make each window come to the front before you can click its button. Good luck.

tell application "System Events"
    repeat with theProcess in processes
        if not background only of theProcess then
            tell theProcess
                set processName to name
                set theWindows to windows
            end tell
            set windowsCount to count of theWindows

            if processName is "Google Chrome" then
                say "Chrome woo hoo"
                say windowsCount as text
            else if processName is not "Finder" then
                say processName
                say windowsCount as text
                if windowsCount is greater than 0 then
                    repeat with theWindow in theWindows
                        say "found a window of " & processName
                        tell theProcess
                            set frontmost to true
                            tell theWindow
                                click button 2
                            end tell
                        end tell
                    end repeat
                end if
            end if
        end if
    end repeat
end tell

这篇关于列出所有应用程序的所有窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆