Pass a parameter (like app name) to the Force Quit & Relaunch action?

Hi,

How can I pass a parameter to the Force Quit & Relaunch action? I’m trying to create a macro that can be triggered to relaunch any frozen app. When an app is frozen it might not necessarily be the Frontmost and I don’t want to create a macro for every single app on my system that can possibly freeze.

Thanks in advance.

Leo

1 Like

Actions that take applications generally cannot be configured to work on an application specified in a variable, so your only solution would be to implement the force quit and relaunch functionality yourself (or to have a variety of Force Quit and Relaunch actions, each configured for a possible application, and select the desired one with an If Then Else action, but that is clearly problematic as well).

A final option, which might actually work ok for this case, would be to use the AppleScript do script command of the Keyboard Maestro Engine to execute a Force Quit and Relaunch based on the XML of the action. Since you could adjust the XML to match the desired application, that would presumably work.

Hey Leo,

As Peter said the KM action doesn't allow for parameters, but between AppleScript and the shell you can do anything you want.

tell application "System Events"
   set appList to name of processes whose background only is false
end tell

tell current application
   set theApp to choose from list appList default items (first item of appList)
   if theApp is not false then
      set theApp to item 1 of theApp
      set shCMD to "killall " & theApp & "; " & "open -a '" & theApp & "'"
      do shell script shCMD
   end if
end tell

--
Best Regards,
Chris

Hi Chris, but where do I pass the argument in this shell and applescript?

Thanks Peter. This seems to complicated for my limited knowledge :slight_smile: Thanks for the reply anyway!

It would be heaps cool if we could pass a variable to those KM actions Peter.

Like Force Quit and Relaunch %ApplicationPath%

Just a suggestion.

Cheers,

Hey Leo,

The script pops-up a list of available apps for you to choose from, although these are the standard apps you’d see in the dock and not any of the background-only stuff.

It’s similar to the Force-Quit dialog, except it restarts the app after killing it.

If you want something simpler here’s a straightforward shell script:

#! /usr/bin/env bash
appToKill="App Factory";
killall "$appToKill";
open -a "$appToKill";

The application App Factory can be represented by a Keyboard Maestro variable.

appToKill="$KMVAR_My_Variable_Name";

So you can easily pass parameters from other actions into an Execute Shell Script Action.

Note: You don’t say anything about how you’re discovering an app is frozen or by what mechanism you want to try to pass its name to a KM-Action.


Best Regards,
Chris

Hi Chris!

The frozen app is almost always airmail but sometimes other apps freeze too. I was looking for a way to quickly relaunch the app. My idea was to use Alfred + Keyboard maestro, so I would invoke Alfred (cmd+space), type the workflow keyword like "relaunch", space, then alfred would filter me a list of apps as I type and when I hit enter it would execute the KM by passing the app as parameter.

It would work with your second example, using

appToKill="$KMVAR_My_Variable_Name";

But then I found this workflow
http://www.packal.org/workflow/kill-process

That does exactly what I need, so I just edited it so what it would relaunch the app too. Here's a screenshot

Thanks for your help as always Chris. I highly recommend alfred if you don't use it.

Cheers,

Leo

Hey Leo,

Alfred is very spiffy, but I’ve been using LaunchBar since way back.

-ccs

1 Like

This works for some apps but not others. For example, if I trigger it while UAD Console is the front application, it doesn't quit the application, and instead launches the Console app.

I've tried the Alfred route, but it takes a while to show running apps, and then you have to manually search for it (if it isnt already visible in the UI). For my needs, I'd just like to quit and relaunch whichever app is currently in focus.

Hey Neil,

Is UAD Console a normal windowed app and not a background-only app?

What is it's name as shown by macOS?

-Chris

Good question! The OS sees it as UA Mixer Engine so I guess that's the problem right there.

1 Like