I am working on converting over my QuicKeys macros to Keyboard Maestro and I am not finding a way to have Keyboard Maestro execute a key command if a window exists in an application. The window may not be in the front but if a window with a given title exists (i.e. The Mixconsole of Cubase) then press F3 twice to hide and then open the mix window in focus, if it doesn't exsist then only press F3 once to open the mixer. That way no mater what when I press F3 it always brings the mix window to the front.
Attached is a screenshot from how I was doing this in QuicKeys if it helps at all.
The only current way is to iterate through the windows and check each window title. You can do it in Keyboard Maestro using the For Each loop, with a numeric range, and the WindowName text token:
Then check whether if any of the windows match your requirements.
Thanks Peter, that is greek to me what you typed, I tried it several different ways but I am too new to understand how to implement that. Seems like I could use "If Then Else" for "Bring Window(s) With Name Containing"

to the front and then when it fails it will press the key command, if it is not in the front it will bring it to the front and not execute the key command, if it is already in the front then it won't do anything more (it wouldn't hurt if Keyboard Maestro attempted to bring it to the front even if it already is). There is nothing that I can find like AppleScript "Try" and "else" statements. If Then Else action doesn't allow me to use all the same actions that are found in Keyboard Maestro like the "Bring Window(s) with Name Containing" action.
I'll mess around with what you posted some more and see what I can figure out with that in getting it to work.
Thanks Peter I was finally able to get this to work. Very different then what I am use to in QuicKeys but great to finally one alternative method.
Cubase - Mixer Focus.kmmacros (32.6 KB)
1 Like
Hey Skillet,
Thatâs great! ProgressâŚ
Hereâs the more normal way of looking at flow control in this problem.
IF window named 'Mixconsole' exists AND front window is NOT named 'Mixconsole'
Bring window 'Mixconsole' to front
ELSE
Select menu 'Devices' > 'MixConsole'
END IF
Thereâs nothing wrong with the way youâve done it, but that wonât work in every case - so keep in mind alternative methods.
KMâs Window-Exists will be easier in future, but hereâs a work-around for now:
tell application "System Events"
if quit delay â 0 then set quit delay to 0
tell process "Finder"
return window "Downloads" exists
end tell
end tell
Note that the app System Events is talking to must be labeled PROCESS - tell process âFinderâ.
You can also do something like this:
tell application "System Events"
if quit delay â 0 then set quit delay to 0
tell process "Finder"
return name of windows whose name contains "Downloads"
end tell
end tell
-Chris
Thanks ccstone, a lot of great tips, I was trying to actually think of something like that. I can see that being the solution in many cases. The only thing I see different then that and what I did as far as the end result is that at work I use three monitors and the mix window may be in focus and I am scrolling in another window (doesnât bring it to focus). If the mix window was active in another monitor it would then go away.
Anyway I love what you posted, just trying to think out loud through this. Thanks a bunch for all the ideas, I know I will be using them as I convert my macros over the next year and write new ones.
Now I have to figure out why I get some emails from this forum and others donât come. I missed a few of your posts until I just went manually through posts again, so sorry for the delay in saying thanks!
Hey Skillet,
IF window named âMixconsoleâ exists AND front window is NOT named 'Mixconsoleâ
So in your case the back half of that might be better left off, but you get the idea â you need enough conditions to make the macro work in your particular circumstance. Sometimes itâs few - sometimes itâs many - and often it takes tweaking to get just right.
-Chris
Double-check your preferences on the forum:
And your junk-mail prefs.
-Chris
Thanks Chris, looks like Iâm all set now I needed to have the last box checked âDo not suppressâŚâ.
I have to say that the way this forum works is the best I have ever seen, I absolutely love it, and havenât seen any others like it. The tips from the email that was sent when I signed up was very helpful. Anyway sorry to derail the thread I started, thank you for all the tips.
1 Like