1

I would like to access the frontmost tab being displayed in Safari and retrieve the URL using the JavaScript Automation scripting in Yosemite Script Editor. I can get the first window, first tab url using code like:

Application('Safari').windows[0].tabs[0].url()

I can't figure how to find which window and tab is actually the one being displayed frontmost currently though.

Jamie Hamick
  • 2,193
  • 2
  • 14
  • 15

1 Answers1

2

windows[0] would normally be frontmost and is the equivalent of doing:

window 1

Then use currentTab

Application('Safari').windows[0].currentTab.url()
markhunte
  • 6,805
  • 2
  • 25
  • 44
  • That "works" as well as what I posted. I consider this a bug as it only "works" if Safari is visible. If Safari is hidden or in a different Space then it always returns the "oldest" window and not the "front" window. I've submitted a bug report to Apple. – Jamie Hamick Apr 14 '15 at 19:04