How to maximize Safari window with JavaScript for Automation (JXA)?

How can I maximize the Safari application window using JXA?

Replies

This is an AppleScript that does what you want:


tell first window of application "Safari"

set isZoomable to zoomable

if isZoomable then

set zoomedAtFirst to zoomed

set theBounds to the bounds


copy theBounds to theNewBounds

set the third item of theNewBounds to ((first item of theBounds) + 512)

set the fourth item of theNewBounds to ((second item of theBounds) + 384)


set bounds to theNewBounds

set zoomed to false

set zoomed to true

copy bounds to theFinalBounds

set zoomedAtLast to zoomed

set theVars to {zoomedAtFirst, theBounds, theNewBounds, theFinalBounds}

end if

get theVars

end tell