wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了macos – Applescript – 将窗口带到前台大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我有一个同时打开几个窗口的应用程序. 我想把一个特定的窗口带到前台(我知道它的标题). 目前我正在使用组合键来完成这项任务,但我想尝试一些不同的东西,因为我遇到了这种方法的一些问题. tell application "System Events" set frontmost of process "appIT" to true keystroke "1" using comman
我有一个同时打开几个窗口的应用程序.
我想把一个特定的窗口带到前台(我知道它的标题).

目前我正在使用组合键来完成这项任务,但我想尝试一些不同的东西,因为我遇到了这种方法的一些问题.

tell application "System Events"
    set frontmost of process "appIT" to true
    keystroke "1" using command down
    delay 0.2
end tell
如果您的应用程序是可编写脚本的并且允许设置窗口的索引,则可以执行以下操作(基于 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

切换可见性对于处理切换应用程序时出现的一些奇怪现象是必要的.如果不切换可见性,则当您切换回应用程序时,窗口将不是第一个窗口.不幸的是,这种切换将窗口缩小到底座然后恢复它,一个非常戏剧性的UI中断.

这是我发现处理怪异的另一种方式:

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

大佬总结

以上是大佬教程为你收集整理的macos – Applescript – 将窗口带到前台全部内容,希望文章能够帮你解决macos – Applescript – 将窗口带到前台所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。