Controlling the Mac OSX GUI via Python?
hasan.diwan at gmail.com
hasan.diwan at gmail.com
Thu Jun 30 18:02:43 EDT 2016
>On 6/30/2016 3:22 PM, you wrote:
>> I'd like to use Python to do some simple OSX GUI manipulations such
>> as automatically arranging windows, periodically refreshing
>> applications across multiple desktops, etc.. Is this possible and if
>> so, is there a preferred package?
Please see this page https://docs.python.org/2/using/mac.html. The following will show a window, entitled "Hello world":
#!/pyobjc/virtualenv/path/bin/python
import sys
import os
from AppKit import *
from PyObjCTools import AppHelper
class Delegate (NSObject):
def applicationDidFinishLaunching_(self, aNotification):
'''Called automatically when the application has launched'''
print "Hello, World!"
def windowWillClose_(self, aNotification):
'''Called automatically when the window is closed'''
print "Window has been closed"
NSApp().terminate_(self)
def main():
a=NSApplication.sharedApplication()
delegate = Delegate.alloc().init()
a.setDelegate_(delegate)
frame = ((200.0, 300.0), (250.0, 100.0))
w = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(frame, 15, 2, 0)
w.setDelegate_(delegate)
w.setTitle_(u'Hello, World!')
w.orderFrontRegardless()
AppHelper.runEventLoop()
if __name__ == '__main__':
main()
More information about the Python-list
mailing list