Switch to an application using a variable

I'd like to save an application name in a KM variable.

Then I'd like to swtich to that application using that KM variable

I can't seem to find anyway to use any variables when switching applications. Is this not possible within keyboard maestro ? (I don't want to hack going into a shell script and typing open etc)

You can use @ComplexPoint's plugin to do this:

There's also the Use Variable action that could be useful.

https://wiki.keyboardmaestro.com/action/Use_Variable

2 Likes

Here's another way to solve the problem... (I know the problem with my idea is that you have to hardcode each app, which may mean 10 to 20 switch actions, but at least it works, and it works without scripting or hacking.)

Here's another way, assuming you have the app name (Safari, etc., as appear when hovering their Dock icons) saved in a variable named local_theApp.

Add an AppleScript action with this simple script:

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set theAppName to getvariable "local_theApp" instance kmInst
end tell

tell application theAppName
	activate
end tell

The first four lines are required to get the variable from KM into AppleScript; then the script just tells that app to activate.

-rob.

1 Like