Trigger from Java

While writing some Selenium test cases in Java, I found an non-interactable button that I need to press.

So why not press it with a 'Click on Found Image' action?

I'm currently trying to trigger by Shell script like this:

import java.io.*;
Process p = Runtime.getRuntime().exec("osascript -e 'tell application "Keyboard Maestro Engine" to do script "86FA96C6-5DB4-489F-B1D0-F84A4CF4B857"'");

Unfortunately the macro never runs. What could be the issue and how to troubleshoot?

I don't know much anything about Java, but I suspect that it might have something to do with the quoting.

I would first try this:

"osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"86FA96C6-5DB4-489F-B1D0-F84A4CF4B857\"'"

and if that did not work I would try this:

"osascript -e 'tell application \'Keyboard Maestro Engine\' to do script \'86FA96C6-5DB4-489F-B1D0-F84A4CF4B857\''"

If that still didn't work, I would put the osascript in a separate file, and then call the file:

Process p = Runtime.getRuntime().exec("/path/to/osascript.sh");

However, I have to admit these are all guesses.

1 Like

I think you're on to something with the quoting, although neither of those quote attempts worked. I'm using IntelliJ IDEA and it's escaping quotes with backslashes even when pasted in.

On a happy note, that last one did work, after I made the file executable of course.

MacOS Catalina then sent 2 permission requests to carry it out. But hey, now I have a working button. I wish I could do it with code alone though.

Have you tried one of the other quoting variants as proposed in the snippets for Ruby and Python?

Screen Shot 2020-03-08 at 12.04.11-pty-fs8

Screen Shot 2020-03-08 at 12.04.36-pty-fs8

Or the heredoc method, as in the Perl snippet:

Screen Shot 2020-03-08 at 12.05.11-pty-fs8

2 Likes