Manipulate Newly Opened Window of Preview App

Hi, How can I manipulate new opened window position of Preview App.
manipulate window is easy, the difficult thing is how to test the window is NEW opened window, cause I don't want this window manipulate by KM again every time when this window activates at front.


It's not exactly checking for new windows, but one of the easier ways to do this is to check the front window's current position (or size, or frame, depending on what the manipulation involves) and manipulate it only if it isn't set up how you want:

If this doesn't satisfy your use case, please follow the tips listed here: Tip: How Do I Get The Best Answer in the Shortest Time?
and post again with more details and an upload your current macro.

1 Like

I have two ideas that can test if the window is new opened:
1.calculate how many preview window has opened, So every time calculate the number if its equal to previous number when Preview app activate
but I don't know how to calculate how many Preview window has now?

2.Record the windows name, the way is same with method 1,
but I don't know how to get the Preview windows name?

Is there some reason the idea I suggested wouldn't work? If a window is already where you want it, I don't see why you would need to test if it's new or not. But if there's something more to this use case than what you've told us (again, see Tip: How Do I Get The Best Answer in the Shortest Time?) both your ideas could conceivably work. You can get how many windows are in the front app with the WINDOWCOUNT() function, and you can get a list of all the front app's window titles with the %WindowName%All% token.

1 Like

I have the same question as the OP, and I can explain why testing the window position will not work for my use case. I want to resize every new window to full screen, but I do not want to resize previously opened windows that I have manually resized.

By default, I would like all windows at full size when I initially open the documents. If I have some need to manually resize a window, I do not want it to be resized to full screen by the macro. I have thought of a couple of ways to do this, but they are a bit complicated. I was hoping there was something I was missing in Keyboard Maestro that could decrease the complexity.

Ideally, it seems the easiest method would be a trigger like:

The focused window:
The focused window is new


I just figured out a way to do what I want without it being crazy complicated.

I created the following macro that will be triggered when Preview is active and the front window title changes. It will perform the actions if the title of the front window is not "Open" (i.e. it's not an open dialog) and it is not already open (it's not in a variable containing the name of all windows that were previously open).

IMHO if you maximize a window, that leads to problems.
However if you enlarge a window and leave a border of say 5 pixels, then
everything runs much more smoothly when you manipulate any window.

I customized my solution a bit more so it will not attempt to resize open and save panels. It will only resize newly opened standard windows. The macro is attached. I make no guarantees; I can only tell you it works well on my system (Keyboard Maestro 9.1/macOS 10.15.7).

While this macro targets for window resizing, it could be customized to perform any action on newly opened windows of any app.

Hope this helps someone out:

Maximize New Preview (2.2 KB)

I've been looking for a way to execute an action (in Outlook) when a new window opens and found your post. I was able to modify your script to work for my use case. Thanks!

@peternlewis Any chance we may someday get a native trigger "New window opens" to go along with the similar "Focused window changes" triggers?

I'm not sure how reasonable it is to detect that.

If you do figure out a way to detect it, it would be great to have. Thanks for all the fantastic work you do!