AppleScript的 - 把窗口前台 [英] Applescript - Bring window to foreground

查看:2570
本文介绍了AppleScript的 - 把窗口前台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有好几个窗口同时打开的应用程序。
我想提出一个特定的窗口前台(我知道它的标题)。

目前我使用的组合键来实现这一任务,但我想尝试不同的东西,因为我遇到了一些问题,这种方法。

 告诉应用程序系统事件
    设置进程的最前端appIT为真
    按键1使用命令下来
    延迟0.2
告诉结束


解决方案

如果您的应用程序编写脚本并允许设置一个窗口的指数,你可以做以下(根据<一个答案href=\"http://stackoverflow.com/questions/5682413/how-do-i-make-a-safari-window-active-using-applescript-elegantly\">How我让使用AppleScript(优雅的)?)

一个Safari窗口活跃

 来theApplicationName的raiseWindow为theName
    告诉命名theApplicationName应用
        启用
    设置theWindow为¬的第一项
        (得到他的名字是theName的视窗)
    如果theWindow的索引不是1,则
            设置索引为1
            设置为false可见
            设置为true可见
        万一
    告诉结束
结束raiseWindow

能见度的反复是必要的处理与交换应用发生了一些怪事。如果你不切换的知名度,当您切换离开并返回给应用程序窗口将不会是第一个。不幸的是,这种切换缩小窗口到码头,然后恢复它,一个非常引人注目的UI中断。

下面是另一种方式,我发现要处理的怪事:

 来theApplicationName的raiseWindow2为theName
    告诉命名theApplicationName应用
        启用
    设置theWindow为¬的第一项
        (得到他的名字是theName的视窗)
        如果theWindow的索引不是1,则
            设置theWindow为2的指数
        告诉应用程序系统事件到¬
            告诉应用程序theApplicationName到¬
                按键`使用命令下来
        万一
    告诉结束
结束raiseWindow2

I have an application with several windows opened at the same time. I'd like to bring a specific window to foreground (I know its title).

At the moment I'm using a combination of keys to achieve this task but I'd like to try something different since I'm experiencing some problems with this approach.

tell application "System Events"
    set frontmost of process "appIT" to true
    keystroke "1" using command down
    delay 0.2
end tell

解决方案

If your application is scriptable and allows setting the index of a window, you can do the following (based on an answer in How do I make a Safari window active using AppleScript (elegantly)?)

to raiseWindow of theApplicationName for theName
    tell the application named theApplicationName
        activate
    set theWindow to the first item of ¬
        (get the windows whose name is theName)
    if index of theWindow is not 1 then
            set index to 1
            set visible to false
            set visible to true
        end if
    end tell
end raiseWindow

The toggling of the visibility is necessary to deal with some weirdness that occurs with switching applications. If you don't toggle the visibility, the window won't be the first when you switch away from and back to the application. Unfortunately, this toggling shrinks the window to the dock then restores it, a very dramatic UI disruption.

Here's another way I've found to deal with the weirdness:

to raiseWindow2 of theApplicationName for theName
    tell the application named theApplicationName
        activate
    set theWindow to the first item of ¬
        (get the windows whose name is theName)
        if the index of theWindow is not 1 then
            set the index of theWindow to 2
        tell application "System Events" to ¬
            tell application process theApplicationName to ¬
                keystroke "`" using command down
        end if
    end tell
end raiseWindow2

这篇关于AppleScript的 - 把窗口前台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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