window.KeyboardMaestro.ProcessAppleScript() Not Working in Custom HTMl Prompt

@peternlewis It appears to me that a specific AppleScript is not returning the result when using window.KeyboardMaestro.ProcessAppleScript() in this Custom HTML Prompt.

AppleScript:

tell application "Keyboard Maestro Engine" to get name of variables

Custom HTML Prompt:

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

  <script type="text/javascript">
    function doTest() {
      const test = window.KeyboardMaestro.ProcessAppleScript(
        'tell application "Keyboard Maestro Engine" to get name of variables');
      console.log(`Result: ${test}`);
      document.getElementById("results").innerText = "Result: " + test;
    }
  </script>
</head>

<body data-kmwindow="400, 290">
  <div>
    <button type="button" onclick="doTest()">Test</button>
  </div>
  <div id="results" style="height: 100%">
  </div>
</body>
</html>

Am I doing something wrong? Thanks,

Hey Dan,

It looks like you're trying to return an AppleScript list object.

Did I not see that you need to return text?

-Chris

1 Like

We can certainly get non-results by trying to return some non-atomic datatypes (numbers are OK – though the return is coerced to string, but not dates for example), but here I'm not even getting those from the KM Engine.

Perhaps it's locked / busy / out of bounds in this context ?


locked / busy / out of bounds

(I notice that the Script Debugger Explorer shows a blank not-running screen for Keyboard Maestro Engine while a Custom HTML Action is running).

I did this in the editor:

image

and I got back a comma-separated list of variable names. I just assumed I'd get the same thing, but perhaps the KM Action does something different with the results than the Custom HTML method?

If that's the case, how should I modify the AppleScript so I get back a string?

I don't think that's the issue here – the process seems to be locked in this context.

You may be right, because even this applescript returns nothing, when it should return a string:

tell application "Keyboard Maestro Engine" to getvariable "DND__kmfamWindowPosition"

I just reported the same thing:

1 Like

It looks like the ProcessAppleScript cannot be used to control Keyboard Maestro Engine itself. I'm not really sure why, the error message is not particularly helpful. It may be some sort of security restriction. It does not seem to affect the Execute an AppleScript action, so maybe it is related to however the WKWebView is communicating with the Keyboard Maestro Engine which somehow drops the permissions it is allowed.

I'll continue looking, but currently I have no leads on why this is failing.

2 Likes

Keyboard Maestro is converting the list to a string somehow when it displays the result or saves it to a variable.

In your case above you're just running a bare script that produces a list object in a different context. I would not assume anything about what it should produce.

If you run that script in the Script Editor it'll produce a list object.

By your logic the Script Editor should also produce a csv text list, but it does not.

In any case – this issue doesn't seem to be the crux of the problem.

-Chris

1 Like