나는이 작업을 수행 유래에 애플 스크립트 here의 조각을 발견OS X를 : 파이썬
OS X의 파이썬에서 프로그래밍 방식으로 창을 이동하려고 해요에서 창을 이동,하지만 난 그것을 할 싶습니다 파이썬 또는 다른 "진짜"스크립팅 언어.
이것은 작동하지 않는 제 Python 스크립트입니다. 나는 그들 각각의 아래에 print 명령의 출력을 썼다.
#!/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입니다 :''tell application "System Events"; 응용 프로그램 프로세스 "Finder"의 첫 번째 창 위치를 {20, 20}으로 설정 ; end tell ''' –
파이썬 코드로하고 싶습니까? osascript와 do와 os.system 호출을 사용하지 않는 이유는 무엇입니까? – maranas
하나의 특정 창을 사용하고 싶지 않고 사용자가 창을 선택할 수있는 목록을 표시하기 때문에. 파이썬에서 직접 할 수 있었다면 아마 더 쉬울 것입니다. –