List all sentences containing a search term in KM docs (as MD / HTML)

Realised this morning that I had missed something in the documentation, and that lead to a small experiment with using XPath to harvest things by search term from the KM documentation to linked MD / PDF.

Here is a macro:

Yosemite version which displays Wiki results page as well as Documentation search results
Keyboard Maestro 7 Docs & Wiki ( term search ).kmmacros (28.5 KB)

Earlier version for KM6:
Keyboard Maestro Documentation ( term search ).kmmacros (23.1 KB)


  1. Prompts for a search term like Javascript
  2. Generates a linked Markdown listing of all sentences containing occurrences (with their section headers)
  3. If Marked is installed, shows a rendered version (search term in red)

For reference, a pretty-printed copy of the Safari javascript in the macro: (1.4 KB)

The XPath 1.0 version of the search path is:

//*[not(name()='script') and not(name()='noscript') and not(name()='a') and contains(translate(text(), 'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz'),	translate('%Variable%Term in Help file%', 'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz'))]

( Newer versions of XPath have fn:lower-case() and fn:ends-with() and a number of other very useful functions which make such patterns rather more concise ... )


Ah … there was an oversight in the XPath (excluded any basic terms appearing in the sidebar links, like ‘Variable’, ‘Calculation’ etc.

Now fixed (above)

Hey Rob,

You’ve hard-coded the location of KM’s help file, and that may not work for everyone. A more flexible approach might go something like this:

tell application "Finder"
  set kmHelpFileURL to URL of file ((path to application id "com.stairways.keyboardmaestro.editor" as text) & "Contents:Resources:Keyboard Maestro Help:index.html")
end tell
tell application "Safari"
  make new document with properties {URL:kmHelpFileURL}
  set bounds of front window to {228, 22, 1542, 1196}
end tell


1 Like

Good thinking … thanks, I’ll adjust that

Ver 0.6 (in first post above) adds bullets to the harvested sentences for clearer legibility.

GREAT macro! Thanks so much for sharing.

1 Like

Added (to first post above), an updated version for the Keyboard Maestro 7 documentation.

Having at first missed something which turned out to be in the Wiki pages, I've updated this to

  1. List search hits in the Documentation pages (as before), and:
  2. display a KM Wiki search result page for the same term:

Keyboard Maestro 7 Docs & Wiki ( term search ).kmmacros (29.5 KB)

1 Like

Yes, the wiki pages now have lots of help on specific components of Keyboard Maestro.

1 Like