How do I make a Safari window active using AppleScript (elegantly)?

☆樱花仙子☆ 提交于 2019-12-10 11:16:51

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/5682413/how-do-i-make-a-safari-window-active-using-applescript-elegantly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!