URL (and Title) from Firefox (subroutine)

This subroutine fetches the URL of the currently displayed Web page in the Firefox Web browser and, optionally, the page’s title. Firefox does not support Applescript and so cannot be supported by Keyboard Maestro’s built-in methods.

Pass the following text strings to this subroutine: “no” if no, you do NOT want it to fetch the title of the current tab; or any other text value if you do (e.g. “yes”). The subroutine returns the following text string: the page title followed by the URL on a new line. The page title will be omitted if the input parameter is “no”.

Please see the "Readme" comment at the top of the macro for details.

Why it's a subroutine: I have a macro that calls this and other subroutines for handling various browsers, but that macro is too attuned to my way of working to be worth sharing without a lot of guesswork about other users’ needs.

This macro was written in Keyboard Maestro v10.2. Thanks! :slight_smile:
URL (and Title) from Firefox (subroutine).kmmacros (11 KB)

Keyboard Maestro Export

1 Like

Good thinking using the page info window to get the details. On your macro that I downloaded it looks like your summon the page info window action is simulating the keystroke of cmd+C? That doesn't work for me to bring up the page info window.

1 Like

I knew I'd got that idea from reading a post here and yes, it's near the top here: Get the Browser Page Title & URL for Safari, Chrome, or FireFox
It doesn't look as though the macro there actually uses that technique for some reason.

I don't understand that... The action uses Cmd-I as written, and I've just downloaded and imported the copy posted here, and it still says Cmd-I! Anyway, that's what's needed!

Perhaps this discussion is relevant..? :thinking:

Oh!!! Fascinating. I hadn't realized that the action is based on keycodes. Thanks.

I use Dvorak.

1 Like

Hey Guys,

You can simplify this by getting the window title with AppleScript:

tell application "System Events"
   tell application process "Firefox"
      tell (first window whose subrole is "AXStandardWindow")
         set windowTitle to its name
      end tell
   end tell
end tell

set kmInstance to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
   setvariable "local_FirefoxWindowTitle" instance kmInstance to windowTitle
end tell

And then Cmd-L, Cmd-C to capture the URL to the clipboard.

I was hoping to be able to extract the URL from the location field with UI-Scripting via System Events, but Firefox still doesn't use proper coding for usability.



Hey Guys,

@MikeTheClicker found some interesting stuff here:

Although I think the methods are too problematic to use routinely.



Thank you - it's a pleasant surprise to me that Firefox has enough Applescript support to allow this much.

Since Cmd-L, Cmd-C is still needed, I might stick with what I've got, but I shall experiment. :+1:

1 Like

This is not AppleScript support but Accessibility support – and it's abysmal that you have to turn on VoiceOver to get it to work.

Firefox actually did support AppleScript long ago, but in their infinite wisdom they decided to drop all support ostensibly for security reasons – but I think they were just lazy.

Ah, that explains it, thanks. Although I didn't need to turn on VO to get your script to work in a test macro (I just double-checked that in a new test macro).

Yes, so I vaguely remembered, also that its return has optimistically been an "issue" for many years now.

Maybe they are insufficiently motivated (is that different? :laughing:). These days (across all platforms) Safari is six time more popular than Firefox, so maybe allocating resources specifically for Mac support is seen as expensively supporting a niche within a declining niche... I don't know. I still have occasional reasons to use or at least test Firefox (that's why I put this subroutine together) but it's not an attractive option for Mac, is it.

That script just gets the window title, and that works without having to jump through hoops.

On the other hand – if you want to gain access to objects inside the window you have to turn on Voice Over.

See this script:

How to Get URL of FireFox Current Document? - #7 by ccstone

They had a working sdef (AppleScript Dictionary) for Firefox, and it would have taken minimal effort to maintain it.

1 Like

Hmm... Let's blame Google, I'm always up for that! :laughing:

1 Like