AppleScript - 系统事件错误:禁用辅助设备访问
AppleScript和系统事件有问题。AppleScript - 系统事件错误:禁用辅助设备访问
我已在“系统偏好设置”的“通用访问”首选项窗格中选中“启用对辅助设备的访问”。
当我尝试:
arch -i386 osascript -e 'tell application "System Events" to get the position of every window of every process'
我有这样的错误:
System Events got an error: Access for assistive devices is disabled. (-25211)
你有什么想法?
非常感谢
问题不在于辅助装置。 AppleScript似乎错误地返回错误代码,当它试图访问一个永远不能有任何窗口的进程的窗口(在我的情况下,它是“谷歌浏览器助手”)。
您需要捕捉错误。这个工作对我来说:
tell application "System Events"
set procs to processes
set windowPositions to {}
repeat with proc in procs
try
if exists (window 1 of proc) then
repeat with w in windows of proc
copy w's position to the end of windowPositions
end repeat
end if
end try -- ignore errors
end repeat
end tell
return windowPositions
返回坐标对,如{{1067,22},{31,466},{27,56},{63,22},{987,22名单}} - 你试图得到什么?
在Mac OS X 10.9上,当AppleScript编辑器不允许使用辅助功能时,实际上会发生同样的错误。
这里是你如何启用它:
转到系统预置>安全&隐私>隐私>辅助。
之后,只是检查留给的AppleScript编辑器复选框和错误应该消失。
如果通过'osascript'从命令行运行脚本,您还需要将Terminal添加到启用辅助功能的应用程序中。 – devios1 2015-10-30 22:52:54
与此页面上有关Mac OS X 10.9(Mavericks)的文章类似,要在Mac OS X 10.8上解决此问题(也可能在较早版本的OS X上),您需要确保“启用访问系统偏好设置“的”辅助功能“窗格中启用了”辅助设备“选项。
谢谢,我会努力this.Last的问题,我怎么能确定窗口在船坞(隐藏),或在前面? – Tokytok 2012-04-13 13:38:37