AppleScript:尝试读取启用的 UI 元素时引发错误

编程入门 行业动态 更新时间:2024-10-28 02:34:34
本文介绍了AppleScript:尝试读取启用的 UI 元素时引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如果我从终端运行以下内容

If I run the following from Terminal

osascript -e 'tell application "System Events" to get UI elements enabled'

我按预期得到真"或假"

I get "true" or "false" as expected

但是如果我要创建一个包含以下内容的文件;

But if I were to create a file with the following contents;

#!/usr/bin/osascript

on supportsAssistiveDevices()
  tell application "System Events"
    set isEnabled to UI elements enabled
    return isEnabled as boolean
  end tell
end supportsAssistiveDevices

log supportsAssistiveDevices()

并通过./myfile运行它,我得到以下错误;

and run it via ./myfile, I get the following error;

./hasguiscript:87:106: execution error: An error of type -10810 has occurred. (-10810)

谁能帮忙解释一下为什么会这样?

Can anyone help shed some light on why that might be?

谢谢.

推荐答案

这在 10.9 之前就不起作用了.您不会将 ui 元素作为一种设置启用.您必须启用每个请求访问 ui 元素的应用程序.这是一项安全"功能,没有启用应用程序的自动化方法.所以你的代码已经一年多了.

This hasn't worked since before 10.9. You do not enable ui elements as one setting. You must enable each individual application that requests access to ui elements. It's a "security" feature and there's no automated way to enable an application. So your code hasn't worked for over a year now.

system preferences->security & privacy->privacy->accessibility

这篇关于AppleScript:尝试读取启用的 UI 元素时引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 14:10:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915955.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   错误   AppleScript   UI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!