Applescript to Maximise Window

Hi, I’ve been trying to find a way to do this…I tried a bunch of different scripts, but most don’t seem to work with modern Mac OS…

All I want to do is Maximise a Window.

Closest I came was this one, but the problem is, it just toggles between two states.
I want to only maximise it.

tell application "Music" to activate
tell application "System Events"
	perform action "AXZoomWindow" of (first button whose subrole is "AXFullScreenButton") of (first window whose subrole is "AXStandardWindow") of (first process whose frontmost is true)
end tell

Thanks for any help!

This doesn’t require GUI scripting, because full screen property of Music.app windows is settable directly:


tell application "Music"
	activate
	set full screen of window 1 to true
end tell

.
If Music.app wasn’t scriptable, then you would have to use GUI scripting:


tell application "Music" to activate
tell application "System Events" to tell process "Music"
	set value of attribute "AXFullScreen" of window 1 to true
end tell

Apple distinguishes between setting an app to fullscreen and maximizing an app’s window.

https://support.apple.com/guide/mac-help/use-apps-in-full-screen-mchl9c21d2be/mac

https://support.apple.com/guide/mac-help/work-with-app-windows-mchlp2469/mac

If the script is only going to be used with the Music app, and if the usable area of the OP’s screen doesn’t change, the following should do what the OP wants (change the bounds to suit). We probably need some clarification from the OP.

tell application "Music"
	set bounds of window 1 to {0, 25, 1920, 1080}
	activate
end tell

This suggestion will maximize the Music window utilizing NSScreen’s visibleFrame property, which is defined by Apple as:

use framework "AppKit"
use framework "Foundation"
use scripting additions

tell application "Music"
	set bounds of window 1 to my getDisplayBounds()
	activate
end tell

on getDisplayBounds()
	set theScreen to current application's NSScreen's mainScreen()
	set {{aF, bF}, {cF, dF}} to theScreen's frame()
	set {{aV, bV}, {cV, dV}} to theScreen's visibleFrame()
	return {aV as integer, (dF - bV - dV) as integer, (aV + cV) as integer, (dF - bV) as integer}
end getDisplayBounds