1

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.

Erik Tjernlund
  • 1,963
  • 13
  • 12

2 Answers2

0

It's strange you say the order of the windows array did not help, because it's supposed to: by definition, the "first" window is the frontmost one. Also, Safari windows do not have URLs; they have tabs which have URLs. Therefore, all you should need is this:

safari.windows[0].currentTab.URL
Chris N
  • 905
  • 5
  • 10
-1

You can use applescript

tell application "Safari" to get URL of front document
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144