I'm trying to get the URL of the front-most, active Safari window (Safari 5.2 running in Mountain Lion Developer Preview 2) through the ScriptingBridge, but can't find any property to determine if the window is the front one.
SafariApplication *safari = [SBApplication applicationWithBundleIdentifier:@"com.apple.Safari"];
for (SafariWindow *window in safari.windows) {
if ([window visible]) {
// Top most, active window?
}
}
This does not work — if I have two open Safari windows, both are visible
.
Neither does using the index
property of the SafariWindow
nor the order of the windows array.
There is an Automator action called "Get current Webpage from Safari" that does work, so it should be possible, but I can't see how.