Noob question, how to target any window I want?


Hi guys, I'm a noob with Keyboard Maestro but know a little bit of Autohotkey from Windows. I have attached two images that try to explain what I want to do with KM, but I'm stuck because I can't seem to get KM to target the window I want. I'm using Christopher Stone's "List Windows Keyboard Maestro Can See v1.1" and the windows I wanna interact with appears blank. Am I doing something wrong?

Use “press a button” command and choose “save” button
I think the window doesn’t have a name

You can make sure there is a save button exists first then ask keyboard maestro to press it

2 Likes

Regarding your other question, about how to "resize to full screen the main window", I don't have After Effects, but I do have Pages, and how I got Pages to work was to change your option from "Front Application" to "Pages" and then insert the name of the window (which was the name of the file I was editing) into the box above it. I suspect that is your mistake here.

I think part of your problem is that you don't "target windows" in order to use many KM actions. Some KM actions require that an app be active (ie, the name is in the menu bar) but some don't even require that. And many windows are not "targetable," but some KM actions will work on those windows despite that.

Thank you for your advice RazMastero! Press a button worked!

@Airy, can Keyboard Maestro activate a window based on the main executable? Sorry for using Windows terms. In Windows, Autohotkey can activate a window based on the process that is running.

For clarity -- that's because, in the Mac world, that is a "dialog" and not a "window".

KM has lots of different Triggers, and you'll see that one is the Application Trigger. So you can have a macro run when a particular application is launched, activated, quit, and so on.

You can also use the "Availability" options in a Macro Group to control when a macro is "Active" -- available to be triggered. That lets you have two macros with the same trigger, one of which only works when (for example) Safari is the active app and the other is only available when TextEdit is frontmost.

Those, along with a macro that has some "Manipulate a Window" actions, can allow you to do all sorts of things. If you describe what you are trying to achieve people will be able to give some suggestions.

1 Like


Thanks for your reply @Nige_S. I attached a new screenshot that hopefully explains what I want Keyboard Maestro to do when I'm using After Effects.

Adobe, in their infinite wisdom, roll many of their own "dialogs" rather than using the OS to do it -- note the differences between this and the one from the Audacity screen shot, particularly the presence here of the non-standard buttons in the top-left corner.

So this time it is, in fact, a window...

Because it is a window and it is the frontmost window of After Effects it will have an "index" of 1. The main window behind it will have an index of 2. You could just target the window with the index of 2:

image

...but that will break when you don't have the "Save As" or other dialog open.

If you only ever have one "proper" window open in After Effects (I'm guessing it's single window, documents as tabs, like other Adobe apps) you can get sneaky and target the backmost window, which has an index of -1:

image

If you might have more than one window open you'll need to try something else... Let us know!

I copied your screenshot of setting the window index to -1 but it doesn't work, went all the way to -15 but the main After Effects window doesn't budge. Is there a way to list an application's current window indexes so I can target the main window? Sorry if that didn't make sense. When I press Command Shift S to Save As, the dialog box launches maximized hahaha!

Any other ideas how I can efficiently implement this?

If it follows some macOS conventions, that dialog remembers the last size it was used. Just resize it manually, then open it again—better?

-rob.

How are you triggering the macro? Is After Effects the active app when you do? There's also the chance that the "Save As" window blocks any interaction with the main one -- it doesn't in Acrobat or InDesign, but it might in After Effects.

It's quite simple -- the front window is 1, the next back is 2, then 3... -- so it's just the current "z order". Negative indexes work the same but from back to front.

You target the window by name instead, but that will be more complicated as I'm guessing that the main window's title can change and there will be more than one "dialog" window title you'll want to ignore.

I have the macro trigger upon After Effects' launch, placed in the Global folder in KM, but with that I gotta be careful not to activate another app as After Effects is launching (like Finder) or else that gets maximized instead. :smile: Then I have this duplicate macro on the screenshots I posted set to trigger when I activate After Effects, set available only in AE.

Test by triggering the macro manually with your ⌃⌥⌘F combo when After Effects is frontmost. If you can get that working you'll know you can target the correct window. It'll then be a case of having your macro wait for the windows to be available before it does the resize -- there's a good chance that there's a delay between "After Effects is activated" and After Effects making its windows available for manipulation.

Yes the manual ⌃⌥⌘F combo works, but that's because I have that target "the front window," when I'm sure I have AE active haha! I was hoping there was a way to make KM absolutely guarantee AE is always maximized, even when I manually resize the window, like a persistent check.

Yes, but your original problem was to resize the "main" window when a "dialog" window was frontmost. One thing at a time!

If you now have a way to maximise the main window manually, regardless of whether or not a dialog is up, you can now move onto the next stage. There's a "The focussed window's frame changed" trigger you could use so that whenever you dragged the window smaller it would snap to maximum again -- if you dragged it to another display it would snap to that display's maximum.

Once you've got that working you can look at the waiting problem. The "Pause Until" action will be useful for that, perhaps with a "front window exists" condition.

What am I missing here, I already set a Pause until Premiere Pro is active, as well as a trigger to activate the macro once Premiere is active, but it still doesn't kick in. I just want to maximize the Premiere window. (See video)
VIDEO

It would help if you were showing your menu bar and the KM Engine icon -- that way we'd be able to see if the macro ran and, importantly, when it finished.

My guess is that there is a delay between Premiere Pro being the active app (when macro triggers/unpauses) and the window becoming "available". Test that by adding a 5 second pause between the two actions in your macro.

If that solves the problem, try changing your first action's pause condition to be "front window exists" and delete the hard-coded pause.

Note that you don't need, and probably don't want, the "application launches" trigger. If, for some reason, you do launch Premiere in the background then you don't want to be messing around with the front window of the frontmost application -- because that won't be a Premiere window! If you launch Premiere "normally" it will also "activate" and that will trigger your window resize.

How would I make Keyboard Maestro target the MS Word window without depending on the document's title/filename?

You need to tell "something" to minimise -- but there's lot's of way of targeting the "something" that don't involve the name.

As always, a good starting point when you're stuck is to do the process manually and note down every decision and action you make to do the job. You can then translate those into KM terms.

So how would you know which of Word's window(s) to minimise? Is it the only window? the Front window? The only document that has (or hasn't) been saved? Perhaps you don't know the complete window title, but it always starts the same or is never "Documentn".

I want it to target all Word windows, of which the filenames will change day to day. With Autohotkey, I can just tell it to target Word.exe. Can I do the same with Keyboard Maestro? Using "windows with title containing Microsoft Word" as shown below doesn't work.

I basically want Keyboard Maestro to move and resize Word when it launches, but currently it's unreliable. And the PowerPoint version doesn't work at all.

You need to get your head out of Windows mode. In macOS the application and its windows are separate things. So you can't

...because Word is an application and can't be moved or resized.

What you need to do is manipulate the windows. First you may need to wait for them to be created, then you get a list of the windows, then you move/resize each window in the list.

Details will depend on how you have everything set up. The default for Office apps is that they open the document gallery on launch. So there's only one window and you can just target the front window of the app. You could trust that the app was also the front application, but I prefer to be explicit:

It really can be that easy. It it might be more complicated, depending on how you've set things up, are opening the app, and so on. So step through your process manually, taking notes as you go, then describe it here (along with any customisations you might have made) and people will be able to help.

1 Like