I'm trying to move around windows programatically from Python on OS X.
I found a snippet of AppleScript here on Stackoverflow which does this, but I'd like to do it in Python or another "real" scripting language.
This is my Python script, which does not work. I wrote the output of print commands below each of them.
#!/usr/bin/python
from Foundation import *
from ScriptingBridge import *
app = SBApplication.applicationWithBundleIdentifier_("com.apple.SystemEvents")
finderProc = app.processes().objectWithName_("Finder")
print finderProc
# <SystemEventsProcess @0x74b641f0: SystemEventsProcess "Finder" of application "System Events" (29683)>
finderWin = finderProc.windows()[0]
print finderWin
# <SystemEventsWindow @0x74b670e0: SystemEventsWindow 0 of SystemEventsProcess "Finder" of application "System Events" (29683)>
print finderWin.name()
# Macintosh HD
finderWin.setBounds_([[20,20],[100,100]])
# no visible result
finderWin.setPosition_([20,20])
The last command (setPosition_) crashes with the following exception.
Traceback (most recent call last):
File "/Users/mw/Projekte/Python/winlist.py", line 17, in <module>
finderWin.setPosition_([20,20])
AttributeError: 'SystemEventsWindow' object has no attribute 'setPosition_'
How can I make the setBounds command work?
tell application "System Events" ; set position of first window of application process "Finder" to {20, 20} ; end tell
– Siret