How to resize window to Fill Screen?

I want to have a window “fill” the screen, which can be done manually by selecting a window and then pressing the ctrl+globe+F keys simultaneously.

Is there a way to automate that with keyboard maestro? There are certain Windows that I want to always fill the screen ( not to be confused with fullscreen ) , and when I move the Dock to another display, they have a Dock-shaped gap at the bottom of the screen where the Dock was.

So , when I move the Dock, I want a quick way of resizing these windows to fill the screen.

I’m on macOS 26.5 and KM 11.0.4.

Update

I’m close, except only the front window is resizing. Even though I’m looping through all of the Windows and resizing and moving them in the same way. Internal is the builtin Macbook monitor that VS Code Windows are on.

A few things:

  1. A lot easier to help you were you to include / upload your macro, that way we can download and test it.

  2. I am not at my desk at the moment to test your build but Keyboard Maestro only acts on the frontmost window which is likely why only the frontmost window is being resized, you need to bring each window to the front and then resize the windows as you loop through.

Let me know, happy to jump back in.

There's nothing obviously wrong and the theory works here -- though I'm on Sequoia and with a different physical setup to you.

For troubleshooting:

  1. Change every windowIndex to Local_windowIndex -- there's no point it being a Global when used to walk a Collection
  2. Change the "For Each" to go from WINDOWCOUNT() to 1 "counting downwards"
  3. Add a Pause of a second or two immediately after the "Move" (and still within the "For Each")

The last will give you a chance to see what's happening, reversing the order will stop the "Fill"ed window from hiding the behaviour of the others.

1 Like

I changed the loop to count down instead of up, and change the index to a Local_ name. No change in the behavior. Foreground window is fills the screen, other windows - I opened a total of 3 VS Code windows with different sizes and locations - remain unchanged.

I noticed when I print the WINDOWCOUNT , it’s 1 even though I have 3 application windows opened.

Maximize Windows.kmmacros (7.5 KB)

Hmmm, I downloaded and tried your macro noting the following:

  1. VS Code has a-typical window behaviour; for example, it does not respond to ⌘H. I Googled this and it is known bug.

  2. VS Code's window count also does not work (don't know whether it is related to the bug in 1 above or not), for some reason as you noted (at least in Keyboard Maestro) it always reports 1 window, no matter how many are open. Perhaps @peternlewis or @Nige_S can shed some light as to why.

  3. But.....the below AppleScript does what you want. at least on my MacBook [Note; VS Code's menu bar reads as Code].

tell application "Keyboard Maestro Engine"
	set svLeft to (calculate "SCREENVISIBLE(Main,Left)") as integer
	set svTop to (calculate "SCREENVISIBLE(Main,Top)") as integer
	set svWidth to (calculate "SCREENVISIBLE(Main,Width)") as integer
	set svHeight to (calculate "SCREENVISIBLE(Main,Height)") as integer
end tell

tell application "Code" to activate

tell application "System Events"
	tell process "Code"
		repeat with w in (windows whose value of attribute "AXMinimized" is false)
			try
				set position of w to {svLeft, svTop}
				set size of w to {svWidth, svHeight}
			end try
		end repeat
	end tell
end tell
  1. Were it me, I would parametrize it further to read in i) the Application and ii) desired window position settings as it would allow you to use it as a sub-macro or subroutine.

Let me know whether you need anything further.

A reminder that ⌘H hides an application, not window(s). So if these things are related it isn't directly.

More generally -- VS Code is an Electron app. Whenever it behaves like a "normal" Mac app we have to count that as a lucky bonus!

That said, windows behave as expected in v1.96.0 under macOS 26.4.1 -- bear with me while I quit/relaunch to update...

In v1.127.0 (latest update, 2 days old) the ⌘H shortcut hides the app as expected, as does KM's WINDOWCOUNT() Token:

...and @majorgear's "Maximize Windows" macro works just fine.

@majorgear -- VS Code is a Microsoft app and an Electron app. Double the chance that something gets broken in any update! But perhaps there's another way...

You only care about the frontmost window of Code (if that) since when that's "Fill"ing the screen you can't see the other windows :wink: So why not just

...which should do what you want, compensating for Dock presence on that screen (tested with Dock hiding on and off). Depending on what you mean by

...you could trigger the macro on every VS Code front window change ("Fill" isn't a toggle, so there's no problem doing that when the window is already full). You should be able to add logic to finesse when it does or doesn't happen, but running it "needlessly" will have no impact on your system.

I'd also note that when I turn Dock hiding on and off a "Fill"ed window automatically resizes, even when not frontmost. The same is true when I reposition an always-on Dock. Does that not happen if you move the Dock?

Appreciate the information. As I continue to learn what are the signs of being an Electron app?

Interesting and very curious as I am on Apple silicon + macOS 26.5.2 + VS Code 1.127.0 and neither the macro nor WINDOWCOUNT() work!

Nice!

Sometimes it's obvious:

:wink:

And you get the nagging feel while using them that something isn't quite Mac-like...

The apps are bigger, and generally more resource hungry, because each app has (and runs) its own Electron framework. But the big giveaway is the the package contents:

@Nige_S. appreciate the education and information.