Is there a way I can use Python to control the size and position of a Mac Window?

Generally I want to write a program to run in the background on Mac and when I push a keyboard shortcut, the current active window would be resized and positioned to the way I have set.

Something similar to the tool called SizeUp on Mac.  I think this shouldn't be difficult to implement and would be fun to take a try.

I would appreciate any resources you could point me to.  Thanks.
Who is Participating?
Eoin OSullivanConnect With a Mentor ConsultantCommented:
Do you have a reason you want to use Python?  As pepr explains python is not a good option to manipulate other applications.

I'd recommend you look at AppleScript - as this does allow you certain access to application window parameters

Alternatively you have a selection of utilities that can perform window resizes or manipulate programs such as
QuickKeys -
iKey -
Keyboard Maestro -

You've probably looked at other window layout tools
Optimal Layout -
Divvy -
ShiftIt -
Moom -

I like BetterTouchTool as it has some nice window snapping and incremental resizing and its FREE -
The problem is that the window is represented as a data structure controled by its program, owned by its process. What you want to do is to manipulate with the data of another process. This what OS generally wants to prevent -- the running processes should be as much separated as possible and should not be allowed to interfere with other processes (unless the other process know).
If you have the right privileges, then you might use some programs to control other windows.

For X-windows for example there are tools like

There are probably similiar tools for Mac.

Normally these programs are rather simple to call from the command line and you can use.

subprocess.Popen() of python in order to start the apropriate commands.
thomaszhwangAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.