tisfeng / Easydict

一个简洁优雅的词典翻译 macOS App。开箱即用,支持离线 OCR 识别,支持有道词典,🍎 苹果系统词典,🍎 苹果系统翻译,OpenAI,Gemini,DeepL,Google,Bing,腾讯,百度,阿里,小牛,彩云和火山翻译。A concise and elegant Dictionary and Translator macOS App for looking up words and translating text.
GNU General Public License v3.0
6.4k stars 325 forks source link

dev: 使用AXUIElementCopyAttributeValue返回错误 #505

Closed dengyan1992 closed 2 months ago

dengyan1992 commented 2 months ago

使用这部分代码,AXError getFocusedUIElementError = AXUIElementCopyAttributeValue(systemWideElement, kAXFocusedUIElementAttribute, (CFTypeRef )&focusedElement);返回kAXErrorCannotComplete,或者 AXError getSelectedTextError = AXUIElementCopyAttributeValue(focusedElement, kAXSelectedTextAttribute, (CFTypeRef )&selectedTextValue);返回kAXErrorAttributeUnsupported。一直没有成功,授权了辅助功能。想向各位大神请教一下是什么原因,非常感谢。

github-actions[bot] commented 2 months ago

Hello dengyan1992, Thank you for your first issue contribution 🎉

tisfeng commented 2 months ago

这里不成功,有很多种原因,具体请查看 苹果文档

   /*! The function cannot complete because messaging failed in some way or because the application with which the function is communicating is busy or unresponsive. */
    kAXErrorCannotComplete          = -25204,

    /*! The attribute is not supported by the AXUIElementRef. */
    kAXErrorAttributeUnsupported        = -25205,
dengyan1992 commented 2 months ago

您好,我运行Easydict工程是正常的,然后自己对照该工程调用,辅助功能的权限是开了的,目前没有这个函数没有返回成功过,查看文档也看不出有什么问题,上网查资源调用方法都是一样的,想请教一下大佬,具体会有哪些问题导致不成功

tisfeng commented 2 months ago

这个问题比较复杂,辅助功能权限有时候会有 bug,你可以尝试移除(不是关闭)应用权限然后重新添加。

tisfeng commented 2 months ago

kAXErrorCannotComplete 我没遇到过,kAXErrorAttributeUnsupported 遇到过,表示控件属性不支持,因为不是所有的应用都支持 AXUIElementCopyAttributeValue 这个函数,如苹果自己的 Safari, Mail 等。