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.
thomaszhwangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peprCommented:
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).
0
gelonidaCommented:
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
http://www.semicomplete.com/projects/xdotool/xdotool.xhtml

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.
0
Eoin OSullivanConsultantCommented:
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 https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptX/AppleScriptX.html

Alternatively you have a selection of utilities that can perform window resizes or manipulate programs such as
QuickKeys - http://startly.com/products/quickeys/mac/4/
iKey - http://plumamazing.com/mac/ikey
Keyboard Maestro - http://www.keyboardmaestro.com/main/

You've probably looked at other window layout tools
Optimal Layout - http://most-advantageous.com/optimal-layout/
Divvy - http://mizage.com/divvy/
ShiftIt - https://github.com/fikovnik/ShiftIt
Moom - http://manytricks.com/moom/


I like BetterTouchTool as it has some nice window snapping and incremental resizing and its FREE - http://www.boastr.de/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thomaszhwangAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.