我試圖圍繞窗口從編程移動的Python在OS X上OS X:從Python的
我發現的AppleScript here的#2片段,其做此移動窗口,但我想這樣做使用Python或其他「真正」的腳本語言。
這是我的Python腳本,它不起作用。我在他們每個下面寫下了打印命令的輸出。
#!/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])
最後一個命令(setPosition_)崩潰,出現以下異常。
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_'
如何使setBounds命令起作用?
這是AppleScript的工作原理:'''告訴應用程序「System Events」; 將申請流程「Finder」的第一個窗口的位置設置爲{20,20} ; end tell ''' –
你只是想在Python代碼中完成它嗎?爲什麼不使用osascript和do和os.system調用? – maranas
因爲我不想使用一個特定的窗口,但顯示用戶可以從中選擇一個窗口的列表。如果我能夠直接在Python中完成這可能會更容易。 –