AppleScript ->激活非脚本化应用程序的窗口 [英] AppleScript -> Activate window of a non-scriptable application

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

问题描述

我打开了 2 个Finder"窗口 A &B,A在前面,B在下面,下面的代码片段将B带到最前面:

I have opened 2 "Finder" window A & B, A is in the front while B underneath, the following snippet brings B to the front the topmost:

tell application "Finder"
    activate
    activate window 2
end tell

但对于不支持脚本的应用程序,刚才提到的代码无济于事.

But for applications that do not support scripting, the code just mentioned won't help.

关于激活非脚本应用程序窗口的任何想法.

Any ideas for activating a window of non-scripting application.

推荐答案

在这些情况下,您通常可以求助于系统事件.系统事件知道正在运行的进程的窗口,您通常可以操作这些窗口.像这样的事情会告诉你一些你可以做的事情.只是玩弄代码,看看你是否可以做你想做的事.

You can usually turn to system events in these cases. System events knows about the windows of running processes and you can usually manipulate those windows. Something like this will show you some of the things you can do. Just play around with the code and see if you can do what you want.

tell application "System Events"
    tell process "Whatever"
        properties of windows
    end tell
end tell

窗口的属性之一是它的标题".所以你也许可以使用它.这种方法利用了这样一个事实,即许多应用程序都有一个窗口"菜单,并且在该菜单下多次列出了窗口的名称,您可以通过单击适当的菜单项来切换窗口.所以这样的事情可能会起作用……我的例子使用 TextEdit.

One of the properties of a window is its "title". So you might be able to use that. This approach uses the fact that many applications have a "Window" menu and under that menu many times the name of the windows are listed and you can switch windows by clicking the approprite menu item. So something like this might work... my example uses TextEdit.

tell application "TextEdit" to activate
tell application "System Events"
    tell process "TextEdit"
        set windowTitle to title of window 2
        click menu item windowTitle of menu 1 of menu bar item "Window" of menu bar 1
    end tell
end tell

这篇关于AppleScript ->激活非脚本化应用程序的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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