I want to write a code to resize a window by setting its bounds, and I need to consider where the dock is positioned and the size of the dock. I can get the dock's position and its size, but the problem is the size I'm getting is not in an immediately usable form. For example, when I do:
tell application "System Events"
tell dock preferences
properties
end tell
end tell
I get
{show indicators:true, minimize into application:false, autohide:false, magnification size:1.0, class:dock preferences object, dock size:0.428571432829, autohide menu bar:false, double click behavior:zoom, magnification:false, show recents:true, minimize effect:genie, screen edge:left, animate:true}
How do I translate the dock size of 0.428571432829 into, for example, 100 so that I can set a window (in a 1024x768 resolution) to position x=100, y=0, h=768, w=924
?
Notice x
started after the dock, and the w
is minus the dock width.
{0, 0}
and768
respectively, then—given a menu bar located at the top edge of the screen, with a height of 23px—the window would find itself positioned at{0, 23}
and its height would be745
.bounds
would be the better one to use asframe
was not universally implemented in the first place rather than deprecation being the issue. Butbounds
is only applicable to scriptable applications. For non-scriptable apps (i.e. most) you'll need to manipulate thewindow
by way of System Events, and that will be using thesize
andposition
properties common to all subclasses ofUI element
class objects. Shame the dock is such a pain.tell app id "com.apple.systemevents" to tell process "Finder" to set [screenW, screenH] to the size of scroll area 1
, which in your case will return[1024, 768]
. That way, if you change resolution at any point, your script won't need rewriting.