我如何使用AppleScript(优雅的)一个Safari窗口活跃? [英] How do I make a Safari window active using AppleScript (elegantly)?

查看:739
本文介绍了我如何使用AppleScript(优雅的)一个Safari窗口活跃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管人们可以模拟命令移`用系统事件来改变窗口在Safari中,有没有更好的方式与AppleScript的做到这一点?我可以改变的Safari浏览器的窗口索引,这种改变屏幕上的排序,但并不能让他们活跃。假设你有一个包含大约两个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?

当然,命令移'的作品,所以也许有仅需要对皮肤这只猫的一种方式。

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 index to 1
        set visible to false
        set visible to true
    end tell
end tell

这篇关于我如何使用AppleScript(优雅的)一个Safari窗口活跃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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