问题
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