This macro helps building a fragment URL for a web page. (An URL that points to a section heading on a web page.)
A fragment URL consists of the base page URL and the URL fragment with the fragment identifier. Typically it looks like this:
https://wiki.keyboardmaestro.com/manual/Single_Page_Version#Macro_Actions
The part after the #
is the fragment identifier.
These URLs are especially nice for sharing information, since they scroll the page automatically to the section of interest.
How to use the macro
- Open a web page in Safari
- Select a section heading (or a part of it) with the mouse
- Press the macro hotkey (default ⌘F3) and wait 2 seconds
The complete URL (base URL+#fragment) is now on your clipboard and ready to be pasted.
Alternatively:
- Open a web page in Safari
- Press the macro hotkey (with nothing selected)
In that case the macro collects all fragment identifiers from the page and presents you with a prompt where you can select one.
Techniques
When the macro finds an identifier that matches your selection, it will take the first one and not look further. So be clever when selecting a section heading:
- Select the entire heading, or just one word, or more words.
- Select something unique: do not select a single word that appears in several headings on the page (“the”).
- Your selection may contain Spaces; the macro converts Spaces to “_” or “-” or “”.
- Do not select non-letter chars like * or ? or », because it is uncertain how/if they are represented in the identifier in the html source.
Anyway, if the search fails, it’s not the end of the world. If the macro doesn’t find any match, it will present you with all identifiers of the page. Just as if you had selected nothing. (See above.)
Failure will happen
- Some web pages just don’t have any identifiers. You’ll get a message in that case.
- Many pages have identifiers only for some headings. If you happened to select a heading without identifier the macro will show you all identifiers it has found, so you can select the nearest one.
- Some old pages may use
name="…"
instead ofid="…"
. The macro does not search forname=
.
Other
When the macro has successfully built a fragment URL it will open that URL in a new Safari tab. This way you see immediately if you got the right identifier.
If you want to disable that behavior just delete or disable the very last (green) action in the macro.
Get Fragment URL.kmmacros (15.2 KB)