PyObjC应用程序不允许访问辅助功能API

2024-10-01 00:25:50 发布

您现在位置:Python中文网/ 问答频道 /正文

在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的提示(参见下面的回答和评论)。


Tags: topytestgtbuildapp权限系统
1条回答
网友
1楼 · 发布于 2024-10-01 00:25:50

我不知道为什么这个在cxu Freeze上不起作用,它对使用这个的py2app确实有用设置.py文件:

from setuptools import setup

setup(
    name='main',
    app=['test.py'],
    setup_requires=['py2app'],
)

也就是说,当我启动应用程序时,给它提供可访问性访问权限,然后重新启动我在中看到的应用程序日志记录控制台.app. 在

相关问题 更多 >