Generate Javascript to Click Webpage Element (WIP)

Certainly not – nothing is less XYZ than experimentation, which is the only way of knowing anything at all :slight_smile:

The slight adjustment below seems to work.


The trick, I think, is just using a global (non-local) variable name for the derived JS source snippet.

As KMEngine.doScript() creates its own private local instance, it can read global variables, but can't obtain values of local variables of another instance (e.g. the calling instance, or enclosing macro).


RUN JS from KM variable in browser.kmmacros (4.5 KB)


Expand disclosure triangle to view JS source
Application("Keyboard Maestro Engine").doScript(
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<dict>
		<key>ActionUID</key>
		<integer>99890259</integer>
		<key>DisplayKind</key>
		<string>Variable</string>
		<key>HonourFailureSettings</key>
		<true/>
		<key>IncludeStdErr</key>
		<false/>
		<key>IncludedVariables</key>
		<array>
			<string>9999</string>
		</array>
		<key>MacroActionType</key>
		<string>ExecuteJavaScript</string>
		<key>Path</key>
		<string></string>
		<key>Text</key>
		<string>return ${kmvar.js_Script}</string>
		<key>TimeOutAbortsMacro</key>
		<true/>
		<key>TrimResults</key>
		<true/>
		<key>TrimResultsNew</key>
		<true/>
		<key>UseModernSyntax</key>
		<true/>
		<key>UseText</key>
		<true/>
		<key>Variable</key>
		<string>js_Result</string>
		<key>WebBrowser</key>
		<string>Front Browser</string>
	</dict>
</array>
</plist>
`)
3 Likes

Is this some kind of internet meme I'm not aware of? It's a bit xyzing xyz if you ask me. :upside_down_face:

Thanks so much for the hand-holding through that. I was totally flummoxed!

I've updated the initial post with the current version, which seems to be working very nicely!

3 Likes

:+1:

xyz ... just reaching for a whatever placeholder

(I seem to prefer short variable names, in the Haskell, or perhaps just math, tradition)

1 Like