Apple - Is there a way to exactly position a window?

Here's an example AppleScript that sets the position of window 1 of Quick Time Player to {533, 118}, if it's running and the window exists.

if application "QuickTime Player" is running then
    try
        if (count windows of application "QuickTime Player") is greater than 0 then
            tell application "System Events" to set position of window 1 of application process "QuickTime Player" to {533, 118}
        end if
    end try
end if

This can be saved as a script or application or incorporated into an Automator workflow as a Service and assigned a keyboard shortcut, if you prefer.

Here's an example AppleScript that you can enter the {x, y} position info as a space separated value in a display dialog box:

if application "QuickTime Player" is running then
    try
        if (count windows of application "QuickTime Player") is greater than 0 then
            tell application "QuickTime Player"
                set theReply to (display dialog "Move window to position, e.g.: 533 118" default answer "533 118" buttons {"Cancel", "OK"} default button 2 with title "Enter Windows X Y Coordinates")
            end tell
            tell application "System Events" to set position of window 1 of application process "QuickTime Player" to {word 1 of text returned of theReply as integer, word 2 of text returned of theReply as integer}
        end if
    end try
end if

Note that you can set default answer "533 118" to default answer "", if you don't want a default value set.

enter image description here


The two window manager tools I'd use for this are Moom and Divvy - both offer demo versions so you can try before you buy.

Once you have an automated move/tile/manage tool, you'll start doing this sort of automated management more and more.

  • https://manytricks.com/moom/
  • http://mizage.com/divvy/

I suppose if you wanted to learn AppleScript - that has all the hooks you need to resize the windows, no software to try or load. Open script editor and you can see the details that the window class allows you to script.

  • Set size of window to exact pixels, and place via x, y coordinates

enter image description here

Tags:

Macos

Ui