如何使用 AppleScript(优雅地)激活 Safari 窗口? [英] How do I make a Safari window active using AppleScript (elegantly)?
问题描述
虽然可以使用系统事件模拟 command-shift-` 来更改 Safari 中的窗口,但有没有更好的方法可以用 AppleScript 做到这一点?我可以更改 Safari 窗口的索引,这会更改它们在屏幕上的顺序,但不会使它们处于活动状态.假设你有两个包含 about:blank 的 Safari 窗口——你怎么能把后面的一个放到前面并激活它?
While one can simulate command-shift-` using System Events to change windows in Safari, is there no better way to do this with AppleScript? I can change the index of Safari's windows, this changes their ordering on the screen but does not make them active. Suppose you have two Safari windows containing about:blank -- how could you bring the one in the back to the front and make it active?
当然,command-shift-` 有效,所以也许只需要一种方法来给这只猫剥皮.
Granted, command-shift-` works, so maybe there only needs to be one way to skin this cat.
推荐答案
我还注意到更改索引确实会重新排序窗口,但是新窗口实际上并没有出现在前面.通过玩弄我发现你可以通过玩可见"属性来解决这个问题......
I also noticed that changing the index does reorder the windows however the new window does not actually come to the front. By playing around I found you can fix that by playing with the "visible" property...
tell application "Safari"
set theWindows to windows
set win2 to item 2 of theWindows
tell win2
set visible to false
set visible to true
set index to 1
end tell
end tell
这篇关于如何使用 AppleScript(优雅地)激活 Safari 窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!