How to Best Capture the Title and URL of a Web Page in Firefox

Hi all,

This works well in Safari...

tell application "Safari"
      set Title to name of window 1
      set URL to URL of document 1
   end try
end tell

However, in Firefox this code below fails about 20% of the time (URL NOT CAPTURED)...

Q: is there a better, quicker way to capture the Title and URL in Firefox that works 100% of the time?

tell application "Firefox" to activate
delay 0.5
tell application "Firefox"
   set Title to name of front window
end tell
delay 1
tell application "System Events"
   keystroke "l" using {command down} -- Highlight the URL field.
   keystroke "c" using {command down}
end tell
delay 1

set theURL to the clipboard
1 Like

Unlike Safari and Chrome, Firefox doesn't have an osascript interface (for AppleScript and JavaScript).

The trick, I find is ⌘L

1 Like

Thank you ComplexPoint - I will try this right away!

Hi ComplexPoint,

Your example works great Thanks!

I was able to change a few things:

I set a KM var (kmVarTitle ) to FF Title
I set a KM var (kmVarURL ) to your clipboard example

How to do the following:

Now I need to setup an applescript with 2 applescript vars to get contents set from the KM Vars

Is there a way to set the applescript vars to KM Vars like...

set asTitle to kmVarTitle ???
set asURL to kmVarURL ???

.. not sure how to do that?

THANKS in advance

Assuming that those variables exist, I think the incantations should have this kind of shape:

tell application ("Keyboard Maestro Engine")
    set strTitle to value of (get variable ("kmVarTitle"))
    set strURL to value of (get variable ("kmVarURL"))
end tell

Great I will try this very soon.

Thanks Again!

WOW ComplexPoint - Both Your suggestions worked GREAT! - Now the Firefox page is getting captured EVERY Time (no misses) and I was able to transfer the 2 KM vars to AppleScript no problem!!!

THANKS MUCH for all you kind assistance!

1 Like

Can someone share an example of this working, I tried it out, and it seems a bit slow and bumpy.

I was thinking about using Grease Monkey or something to Grab the URL of a webpage, and
push that to Key Board Maestro, but it seems to throw a CORS Violation. I'm trying to think
of a better way to do this.

There are some Firefox Plugin's that change the Title of the Window to a URL, they seemed to

Any new Ideas for this ?

Browser JS is unable, by design, to produce effects outside the browser – in the broader system in which the browser is embedded.

There are some Firefox Plugins that ...

Browser plugins also evaluate JS in a sandbox, with access to browser windows, but necessarily isolated from the rest of the system.

1 Like

Hey Patrick,

Mozilla removed the Firefox suite from Firefox's AppleScript dictionary long ago.

The only thing that remains is the default AppleScript suite, which is next to useless.

Blame slow and bumpy on them, and please do take the time to complain to them.