Still headaches with Get TTL & URL of FFOX (v11.0.4) …

Can get the URL, but not the TTL (title) of the FFOX page.

As it is impossible to get the FFOX title AFAIK, I want to select the title, and let KM copy it, but this doesn’t work. So I have 2 different clipboards.

Maybe if 1 clipboard gets emptied on the way?
(Pauses are now 1.0 sec)

Any assistance will be much appreciated,
OmarKN

GetO3b TTL & URL of FFOX Macro (v11.0.4)

GetO3b TTL & URL of FFOX.kmmacros (7.7 KB)

This:

doesn't make any sense. The action before it will Copy, wait for the clipboard to change, then put it in the temporaryClipboard named clipboard then proceed to the next action, this Pause Until.

At that point the named clipboard will either have text or never have text (unless you have some other macro running). So at best it should be an Assert action.

This is just going to copy the same thing since nothing has changed. Why would you think it is going to copy the title of the web page?

>This is just going to copy the same thing since nothing has changed. Why would you think it is going to copy the title of the web page?

Because I selected (manually) the title.

The title of any web page is stored in a field named <title> in the source, and we can use this fact to get the title from any page in any browser by searching the returned text of the source.

Here's a little demo macro that activates Firefox, copies the URL, then downloads the source of that URL (temporarily), searches it for the <title> tag, and displays the results in a pop-up window (after saving it to a variable).

Download Macro(s): Get Firefox page title.kmmacros (5.5 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 15.7.1
  • Keyboard Maestro v11.0.4

Run it, and get output like this:

The trickery in the shell script is the -0777 flag on the perl command. This forces Perl to treat the inbound text as one (massive) line, so that the search will pick up both of these formats:

<title>this is the page title>

<title>
    this is the page title
</title>

I had an AI help me write this a while ago, for use in another macro. The two things it did that I couldn't figure out were the multi-line handling, and accounting for attributes on the title tag, which is done by the title[^>]*> piece of the regular expression.

Notice that there is probably still some post processing you'd want to do (depending on the source), and that's where things get interesting, because every site structures their titles differently.

In the case of the Keyboard Maestro forum, you'd (probably) want to strip out everything after the second hyphen from the end, as that's all forum-related stuff.

To handle this, I'd add a Case action, and then just cover the cases I know are special—here's a version of the macro that does that for the forums and for YouTube, for instance:

Download Macro(s): Get Firefox page title with post-processing.kmmacros (7.6 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 15.7.1
  • Keyboard Maestro v11.0.4

Run that version on this forum page, and you get just the page title back:

You might think it'd be slow to grab and search the full page source, but it's not—on a very long web page, the shell script portion of the macro runs in just over a tenth of a second.

Working with the text from a page's source is a good way to work with browsers that don't do AppleScript, and to avoid having to do any manual selection in the GUI. Yes, you may have to do some post-processing, but that's a much simpler thing to do than trying to capture your selection, or otherwise manually interact with the page.

Hope this helps!

-rob.

1 Like

Hey and good day Rob,

This really helped A LOT :slight_smile:

Your 1st macro ( Get Firefox page title.kmmacros (5.5 KB)), is quite enough for me right now!

This will be very useful for many.

/
best regards,
OmarKN

1 Like

I may have pointed this out before but the Copy As Markdown link macro works (capturing title and url) with Firefox.

You can study it to see the approach, essentially:

See:

Current versions kept here:

1 Like

For Opera, both title & URL
by @ComplexPoint

/
best regards,
OmarKN

Not something that I use, or even have installed at the moment, but I clearly tried it at some point – I notice that I wrote a snippet here, and it's possible that it still works:


Generally, the points made by others in that thread still apply.