有几个可能的解决方法可以尝试来解决使用AppleScript与System Events(UI读取)时的速度问题。
delay
命令来添加一个0.2秒的延迟:delay 0.2
减少UI操作:尽量减少对系统UI的读取操作,因为这些操作可能会导致速度下降。例如,只在必要时才使用System Events
来访问UI元素。
缓存UI信息:在脚本的开始阶段,将UI元素的信息缓存在变量中,以便后续的操作可以直接使用这些缓存的信息,而不需要再次访问系统UI。例如:
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
set mainWindow to first window of frontApp
-- 缓存其他UI元素...
end tell
keystroke
命令来模拟按下特定的键盘快捷键:tell application "System Events"
keystroke "s" using {command down}
end tell
尝试这些解决方法之一,或者将它们结合起来,可以改善使用AppleScript与System Events(UI读取)时的速度问题。