AppleScript导出应用调用System Events click报1719辅助访问错误求助
AppleScript导出为应用后辅助访问权限异常(click命令失败,key code可执行)
我遇到一个棘手问题:AppleScript在Script Editor中运行完全正常,但导出为应用程序后,尽管已在「设置>隐私与安全性>辅助功能」中授予权限,仍触发错误:
appname is not allowed assistive access. System Events got an error: appname is not allowed assistive access. (-1719)
脚本中的click命令执行失败,但改用key code 76可以成功,不过这个方案无法适配所有场景,不能替代click操作。
已尝试的无效修复方案
- 移除并重新添加「设置>隐私与安全性>辅助功能」列表中的应用条目
- 操作期间关闭设置面板并重启系统
- 将iTerm添加到辅助权限列表
- 确认脚本未修改文件签名,也没有重复触发权限请求
测试脚本
set runQuit to true set runGetBranch to true set runiTerm to true set runVSCode to true set runBrowser to true set branchName to "dev" set clickTest to true set keyTest to false ------------------------------------------------------------------ --Quit Apps -- ------------------------------------------------------------------ --Quit VS Code if runQuit then tell application "Visual Studio Code" quit end tell tell application "iTerm" quit end tell end if delay 2 ------------------------------------------------------------------ --Get Branch Number -- ------------------------------------------------------------------ if runGetBranch then set branchNameResponse to display dialog "What branch are you checking out?" default answer "ABC-" with icon note buttons {"Cancel", "dev", "Continue"} default button "Continue" if (button returned of branchNameResponse is "dev") then set branchName to "dev" else if (button returned of branchNameResponse is "Continue") then set branchName to text returned of branchNameResponse else --Cancel error number -128 --user canceled script end if end if set clickTestResponse to display dialog "Clicking Off? (testing)" buttons {"Off", "On", "KeyCode"} default button "On" if button returned of clickTestResponse is "Off" then set clickTest to false end if if button returned of clickTestResponse is "KeyCode" then set keyTest to true set clickTest to false end if ------------------------------------------------------------------ --Start iTerm -- ------------------------------------------------------------------ if runiTerm then tell application "iTerm" to activate --Close the initial terminal 3 times (incase default layout was already opened) repeat 5 times tell application "System Events" tell process "iTerm2" tell menu bar item "Shell" of menu bar 1 if clickTest is true then click if keyTest is true then key code 76 tell menu item "Close" of menu 1 if clickTest is true then click if keyTest is true then key code 76 end tell end tell end tell end tell end repeat --Open default Layout tell application "System Events" tell process "iTerm2" tell menu bar item "Window" of menu bar 1 if clickTest is true then click if keyTest is true then key code 76 tell menu item "Restore Window Arrangement" of menu 1 if clickTest is true then click if keyTest is true then key code 76 if clickTest is true then click menu item "Default" of menu 1 end tell end tell end tell end tell end if
希望有遇到过相同问题的开发者提供可行的解决方案,让导出后的应用能正常执行click命令。
内容的提问来源于stack exchange,提问作者Dave
相关产品推荐
相关产品推荐

