Script that opens user input prompt window with button to launch app

Disclaimer: I’m no expert when it comes to AS, not even a newbie, so I hope someone can still help me with this…

I use Keyboard Maestro and for some reason the engine crashes and my macros stop working until I restart the engine. I found the following script that gets triggered when the engine crashes, showing me a notification, which is already a great thing:

repeat
	tell application "System Events"
		if name of every process does not contain "Keyboard Maestro Engine" then display alert "Keyboard Maestro Engine quit!"
	end tell
	delay 5
end repeat

Now what I would like to have, instead of just the notification, would be the same popup, but instead of the OK button, I could have a button that automatically launches the engine. Can this be done?

So basically, where it says “display alert”, I would have something else that would show me the pop up with the “Launch KM Engine” button and would launch it, so I don’t have to go and launch it manually by going to the folder that contains it.

Thank you in advance!

The best approach to run any AppleScript to know if a script work or have error is from Script Editor or better Script Debugger. Specially if we do not know what we are doing. I’m not a user of keyboard maestro and do not know what it could do if a error occurs.

Sorry if that was not helpful to you.

Thank you for the reply.
Maybe I wasn’t clear about what I need…
The issue now is not whether I’m using Keyboard Maestro or any other app, and it’s not about the errors. My goal is to have a script that instead of showing a notification window with an OK button (then I have to go launch Keyboard Maestro Engine manually), I would like to have a script that shows me a window that has a button that I can customize with a name like “Launch KM Engine” and when I click it, it launches the app.

Hope it makes sense

You could open any app with tell block and the command activate.

Thanks again. Unfortunately, as I mentioned, I’m not familiar with AS. I got this other script from an online source and I can “kinda” understand what’s happening there when I read it, but I don’t have the knowledge to actually create something from scratch.

Would you mind sharing it? If it’s too complicated/time consuming for you, it’s ok, I understand.

Lets asume Keyboard Maestro Engine use launch agent… if it crash that you said in your first message. It could be that it start again… that is possible with launch agent.

I do know the application you ask question about have forum: https://forum.keyboardmaestro.com to give you a better answer or more correct and I could.

You could try

tell application "Keyboard Maestro Engine" to activate

Ps. Any person who seek knowledge in life only need an direction. You like to solve a task but you do not like to learn is that what you like to say with your remark.

Hey @tiagorocha1979,

That repeat loop is nasty – you don’t want something like that running continuously on your system.

Something more like this running in a stay-open applet would be more appropriate:

on run
   idle
end run

on idle
   
   tell application "Keyboard Maestro Engine"
      if running = false then
         run
      end if
   end tell
   
   return 10
   
end idle

If I were doing such a thing I’d take the trouble to learn how to do it with launchd.

But… The Keyboard Maestro Engine should not be crashing on you regularly. KM is very, very stable.

Please take the time to make a bug report to Peter N. Lewis – developer of Keyboard Maestro: Contact Keyboard Maestro Support

You might also post on the Keyboard Maestro Forum as @Fredrik71 suggested.

-Chris

Hi tiagorocha1979,
Why don’t you simply do a standard display dialog? If you hit the “OK” button, then the next step is a the launch command you need. Otherwise, you hit cancel to cancel the whole script.

Or better yet: A display dialog with 3 buttons: Cancel, Launch, and OK.
Cancel - cancels the script
Ok - does nothing and the script continues
Launch - launches the app and the script continues

This is simple to code