加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

macos – 列出所有应用程序的所有窗口

发布时间:2020-12-14 02:03:31 所属栏目:Windows 来源:网络整理
导读:我正在尝试编写一个可以调整所有打开窗口大小的applescript脚本.为了确保我到达所有窗口,我正在让我的脚本说出应用程序的名称以及该应用程序的打开窗口数. 有趣的是,当我听到所有打开的应用程序的名称时,我的脚本说他们都打开了0个窗口.我该如何解决这个问题
我正在尝试编写一个可以调整所有打开窗口大小的applescript脚本.为了确保我到达所有窗口,我正在让我的脚本说出应用程序的名称以及该应用程序的打开窗口数.
有趣的是,当我听到所有打开的应用程序的名称时,我的脚本说他们都打开了0个窗口.我该如何解决这个问题?

这是我的代码:

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,使用automator 2.2.4来编写/运行这个AppleScript

解决方法

你必须告诉进程计算窗口.毕竟,这是了解其窗口而非系统事件的过程.

你告诉过程要说出它的名字,例如“将theProcess的名称称为字符串”但是你只使用“说(将窗口计为字符串)”……没有任何过程与此相关联.尝试“计算过程的窗口”.基本上,你有时会告诉流程,有时你不会告诉流程,有时你告诉流程,即使你已经告诉过程,所以你要做两次.这就是你说“说(进程的名称)为字符串”,但该代码在“告诉进程”块中,因此它已被告知进程.

真的,你需要通过你的代码,更准确.提示…如果您想单击窗口中的按钮,则窗口必须位于屏幕的最前面,否则您无法单击它.另一个提示……“名称”已经是一个字符串,因此您不需要将其强制转换为字符串.

顺便说一句,我同意Michael Dautermann对你的帖子的评论……会有一些你无法访问的过程.但随着你的进步,你会发现它.

这是我编写代码的方式.基本上我会在开头使用“tell theProcess”块获取所有变量.然后我可以用这些变量做些事情.我希望有所帮助.请注意,我只是将过程放在最前面,这意味着如果打开多个窗口,它只会单击前窗上的按钮.在单击其按钮之前,您必须添加代码以使每个窗口都显示在前面.祝好运.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读