gpt4 book ai didi

macos - 苹果权限 hell : osascript and Accessibility (Assistive Access)

转载 作者:行者123 更新时间:2023-12-05 06:28:11 26 4
gpt4 key购买 nike

Apple 权限 hell :osascript 和辅助功能(辅助访问)。

错误:不允许使用 osascript 进行辅助访问。 (-1719)

我在名为 QuickenUpdate.scpt 的文件中有一个单行脚本

在脚本编辑器中运行(有效):

tell application "System Events" to tell process "Quicken" to click menu item "Update all Online Accounts" of menu "Accounts" of menu bar item "Accounts" of menu bar 1

在终端中运行(有效):

/usr/bin/osascript /Deployment/bin/Stocks-1.01.03/scripts/QuickenUpdate.scpt

我有一个 shell 脚本 (QU.sh) 来运行它。

#!/bin/bash
. ~/.bashrc
/usr/bin/osascript /Deployment/bin/Stocks-1.01.03/scripts/QuickenUpdate.scpt 2>&1
exit 0

如果我从 BBEdit 中运行 QU.sh,它会起作用。

如果我从终端运行 QU.sh,它会工作。

如果我尝试通过 launchd 运行它,它会失败并显示:osascript is not allowed assistive access。 (-1719).

启动plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>Sec_Stocks_QuickenUpdate.job</string>
<key>Program</key>
<string>/Deployment/bin/Stocks-1.01.03/bin/QU.sh</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>9</integer>
<key>Minute</key>
<integer>45</integer>
</dict>
</dict>
</plist>

您不能将 osascript 添加到辅助访问,因为它不是应用程序!

最令人沮丧的是几周前我确实让它工作了,但不记得是如何工作的。

我不得不对项目进行一些更改并重新部署它(它是使用 ANT 脚本构建和部署的更大项目的一部分)。

您必须克服重重障碍才能让新构建正常工作这一事实很荒谬。

到底要怎么搞定这个权限?

最佳答案

经过大量的尝试和错误...

要使用“系统事件”来控制应用程序(例如:Quicken),shell 脚本和目标应用程序都需要位于系统偏好设置的隐私/辅助功能列表中。 shell脚本无法手动添加。

在系统偏好设置中手动添加目标应用程序。保持列表打开,然后通过 launchd 运行 shell 脚本(我使用“Launch Control”应用程序来运行作业)。

作业将失败,但 shell 脚本现在应该在辅助功能列表中。检查它(打开它)然后脚本应该执行正常。

关于macos - 苹果权限 hell : osascript and Accessibility (Assistive Access),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54578125/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com