How to Get URL of FireFox Current Document?

There is a specific KM Action to get the Chrome URL, but I don’t see how to get the FireFox URL.

Any suggestions?

Hey JM,

You can't — at least not directly.

Firefox isn't scriptable — nor does it abide by Accessibility Standards — so you can't use System Events and UI-Scripting to operate on its windows beyond moving them around an resizing them.

That leaves us with brute-forcing the interface.

Activate Firefox
Type Cmd-L
Copy

-Chris

3 Likes

Thanks Chris. As usual, you have a great solution.
Works great. Thanks for all your help.

1 Like

It won't help @JMichaelTX now :frowning: but Cmd+L / Cmd + C is still - in late 2021 - the only way to get the URL.

I wish to point out that OCR is probably another way, as long as the URL doesn't overflow the address bar. Monterey's new OCR is fabulous and probably would work fine for this purpose.

1 Like

I haven't tested these myself but may be of use if wanting to support FF:

1 Like

Very interesting if highly troublesome... :sunglasses:

I can get this to work:

Firefox ⇢ Extract URL from Location Field with UI-Scripting v1.00.kmmacros (7.1 KB)
Keyboard Maestro Export

But it's slow, ugly, and noisy...

The shell script stuff looks really troublesome and perhaps not too secure...

-Chris

1 Like

Cmd+L + Cmd+C works in my automation, perhaps with a small delay.

(I use the result in a regex to confect a file name. In my case it's a localhost URL that I need to deconstruct - to save a graphic away.)

1 Like

tell application "System Events"
-- Specifica il nome dell'applicazione, ad esempio "Firefox"
tell process "Firefox"
-- Naviga fino al campo di testo specifico
set theTextField to text field 1 of combo box 1 of toolbar 2 of group 1 of window 1

	-- Estrai il valore
	set theURL to value of theTextField
end tell

end tell

-- Mostra il valore estratto
display dialog "L'URL estratto è: " & theURL

2 Likes

Very good.

This pair of lines:

set theTextField to text field 1 of combo box 1 of toolbar 2 of group 1 of window 1
set theURL to value of theTextField

– can be replaced with:

set theURL to value of text field 1 of combo box 1 of toolbar 2 of group 1 of window 1
1 Like

This is great! Thank you both of you!

This is how I've now set it up in my macros:

Execute an AppleScript.kmactions (1.1 KB)

8264dcd4206cab5c768dcd1ba814918014ce9e63


Script text
tell application "System Events"
	tell process "Firefox"
		return the value of text field 1 of combo box 1 of toolbar 2 of group 1 of window 1
	end tell
end tell

And here's what it replaces:

!
1428567227714ecb879b2bdc94e44d9932d7c6b6


EDIT: Cropped the unnecessary wide images

2 Likes

Very neat. Unfortunately, once I had swapped in that revised script, it failed due to System Events declaring an "invalid index", and now the older versions of script won't work either! :laughing: (That's also the case in Script Editor).

That's also the error message that I had already encountered when testing such scripts on browsers derived from Firefox, so at least everything's consistent now.

Never mind; as Firefox often reminds us, "Firefox couldn't…"™