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.
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.
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
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.
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.
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.