There is a specific KM Action to get the Chrome URL, but I don’t see how to get the FireFox URL.
Any suggestions?
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
Thanks Chris. As usual, you have a great solution.
Works great. Thanks for all your help.
It won't help @JMichaelTX now 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.
I haven't tested these myself but may be of use if wanting to support FF:
Very interesting if highly troublesome...
I can get this to work:
Firefox ⇢ Extract URL from Location Field with UI-Scripting v1.00.kmmacros (7.1 KB)
But it's slow, ugly, and noisy...
The shell script stuff looks really troublesome and perhaps not too secure...
-Chris
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.)
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
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
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)
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
!
EDIT: Cropped the unnecessary wide images
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! (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…"™