Just in case you use an app that does NOT react to AXZoomWindow in a standard way (like BBEdit) or you happen to have different "favourite" settings for windows of different apps (I like Mail less wide than Safari), I wrote a script that maximises an app's frontmost window and RESETS it to your individual preferences.
Here are some issues that I met and had to solve:
1.) "frontmost process" when called in a script is "System Events" or "ScriptEditor" – set visible to 0.
(Does NOT apply to Karabiner shortcuts.)
2.) Max. values of desktop are defined by size of scroll area 1 of process "Finder"
3.) Menu bar's height on my system is 22px so I had to subtract them in various places
4.) I combined values for position & size in a mutual variable per app – Replace with your own !
5.) In order to only address apps you want to "Zoom" there is "maxMin" to exclude others –
add or delete apps as you like
6.) Of course you'll need to register the script/app with "Assistive Access" (Security/System Prefs)
7.) Either shortcut this script as a "Service" (via Automator) in Sys-Prefs, Keyboard, shortcuts, …
8.) … or use the ingenious key-remapper Karabiner Elements with a simple "Complex Modification":
"from": {"key_code": "m", "modifiers": {"mandatory": ["left_option"]} },
"to": [{"shell_command": "osascript ~/.config/myScpts/maxMin_zoom.app"}], **
"type": "basic"
≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈
(** path and name: your choice)
which delivers a suitable shortcut on the spot – I settled for "Opt-M" as most "Z" combos are in use.
Here's the script (DELETE lines 2 & 3 for Karabiner):
tell application "System Events"
set visible of first process whose frontmost is 1 to 0
delay 0.2
set dTopSize to size of scroll area 1 of process "Finder" as list
set maxPos to {0, 22}
set realApp to first process whose frontmost is true
set froAppName to (name of first process whose frontmost is true) as string
set maxMin to true
if (froAppName is "BBEdit") then
set appBounds to {0, 22, 888, (item 2 of dTopSize) - 22}
else if (froAppName is "Safari") then
set appBounds to {38, 22, 1372, (item 2 of dTopSize) - 22}
else if (froAppName is "Mail") then
set appBounds to {53, 22, 1314, (item 2 of dTopSize) - 22}
else
set maxMin to false
end if
if maxMin then
if item 1 of (size of window 1 of realApp as list) is not equal to ¬
item 1 of dTopSize then
set position of window 1 of realApp to maxPos
set size of window 1 of realApp to {(item 1 of dTopSize), ¬
(item 2 of dTopSize) - 22}
else
set size of window 1 of realApp to {item 3 of appBounds, ¬
item 4 of appBounds}
set position of window 1 of realApp to {item 1 of appBounds, ¬
item 2 of appBounds}
end if
end if
tell realApp to set frontmost to true
end tell