Friday, December 2, 2022

#1 2022-11-24 11:15:04 am

simcc
Member
Registered: 2022-05-10
Posts: 2

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.

Applescript:

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!

Last edited by simcc (2022-11-24 11:30:14 am)

Offline

 

#2 2022-11-24 11:24:32 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2588

Re: Applescript to Maximise Window

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

Applescript:


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:

Applescript:


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

Last edited by KniazidisR (2022-11-24 11:43:30 pm)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 15.6.1
Ram: 4 GB

Offline

 

#3 2022-11-25 06:44:49 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1516

Re: Applescript to Maximise Window

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

https://support.apple.com/guide/mac-hel … 21d2be/mac

https://support.apple.com/guide/mac-hel … lp2469/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.

Applescript:

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

Last edited by peavine (2022-11-25 10:32:39 am)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#4 2022-11-25 03:20:50 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 1089

Re: Applescript to Maximise Window

Other approach...
if you like to include NSScreen and use AS bounds and do not like to have auto-hide menu bar.

Applescript:

use framework "Foundation"
use scripting additions

set screenSize to {0, 0} & item 2 of (current application's NSScreen's mainScreen())'s frame()
tell application "Music" to set bounds of window 1 to screenSize

Last edited by Fredrik71 (2022-11-25 03:24:54 pm)


Node-RED makes it easy to automate IoT

Offline

 

#5 2022-11-25 06:46:39 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1516

Re: Applescript to Maximise Window

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

This rectangle defines the portion of the screen in which it is currently safe to draw your app’s content. The returned rectangle is always based on the current user-interface settings and does not include the area currently occupied by the dock and menu bar. On Macs that include a camera housing in the bezel, this rectangle does not include the bezel or the visible areas on either side of the bezel.



Applescript:

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

Last edited by peavine (2022-11-25 06:50:13 pm)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)