gpt4 book ai didi

macos - Applescript-将窗口置于前台

转载 作者:行者123 更新时间:2023-12-04 01:28:10 26 4
gpt4 key购买 nike

我有一个同时打开多个窗口的应用程序。
我想将一个特定的窗口置于前台(我知道它的标题)。

目前,我正在使用组合键来完成此任务,但由于这种方法遇到了一些问题,因此我想尝试一些不同的方法。

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-将窗口置于前台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13173514/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com