在osxmaverick上,我有一个基于PyObjC(python3.3)的简单应用程序
test.py
class MyDelegate(NSObject):
def applicationDidFinishLaunching_(self, sender):
NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSKeyDownMask, lambda event: NSLog("hello"))
NSApp.activateIgnoringOtherApps_(YES)
delegate = MyDelegate.alloc().init()
app = NSApplication.sharedApplication()
app.setDelegate_(delegate)
menu = NSMenu.alloc().initWithTitle_("My Menu")
app.setMainMenu_(menu)
window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
NSMakeRect(0, 0, 100, 100),
NSTitledWindowMask,
NSBackingStoreBuffered,
NO
)
window.setTitle_("my app")
window.makeKeyAndOrderFront_(None)
windowController = NSWindowController.alloc().initWithWindow_(window)
AppHelper.runEventLoop()
用它
^{pr2}$并在“系统首选项->隐私和安全->辅助功能”中为终端提供可访问性访问权限
我可以看到全球监测系统工作。在
然后我把它冻住了
python3 setup.py bdist_mac
以
build/Test.app
与
open build/Test.app
我在OSX系统日志中看到错误
universalAccessAuthWarn[546]: AccessibilityAPI: pid 3809, is not allowed to access the accessibility API. Path: /path/to/build/Test.app/Contents/MacOS/test
我在“System Preferences”->;“Privacy&;Security”->;“Accessibility”中为“test”启用了访问权限,但这不起作用。在
我错过了什么?在
更新: 可能是cx2app的问题,使用py2app(0.8)使全局事件监视程序工作。感谢Ronald Oussoren的提示(参见下面的回答和评论)。
我不知道为什么这个在cxu Freeze上不起作用,它对使用这个的py2app确实有用设置.py文件:
也就是说,当我启动应用程序时,给它提供可访问性访问权限,然后重新启动我在中看到的应用程序日志记录控制台.app. 在
相关问题 更多 >
编程相关推荐