我正在测试我将在我的OSX应用程序中使用的Applecripts。 我在下面的点击按钮命令后得到了6秒的延迟。 经过一些研究,似乎这是一个已知的问题。 我觉得有趣的是,如果我使用商业应用程序QuicKeys执行相同的操作 按钮点击没有延迟,所以我假设他们找到了解决方法。 有人有什么想法吗?
tell application "System Events"
tell process "Pro Tools"
set frontmost to 1
click button "Track List pop-up" of window 1
-- 6 seconds delay before next command is sent
key code 36 -- return key stroke
end tell
end tell
答案 0 :(得分:2)
遇到了同样的问题并通过在ignoring application responses
块中包含导致延迟的点击来解决它。这是一个快速摘要:
旧代码(导致延迟6秒)
tell application "System Events" to tell process "SystemUIServer"
set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
click bt
tell (first menu item whose title is "SBH80") of menu of bt
click
tell menu 1
if exists menu item "Disconnect" then
click menu item "Disconnect"
else
click menu item "Connect"
end if
end tell
end tell
end tell
新代码(不延迟)
tell application "System Events" to tell process "SystemUIServer"
set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
ignoring application responses
click bt
end ignoring
end tell
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "SystemUIServer"
tell (first menu item whose title is "SBH80") of menu of bt
click
tell menu 1
if exists menu item "Disconnect" then
click menu item "Disconnect"
else
click menu item "Connect"
end if
end tell
end tell
end tell
请在下面列出的主题中查看详细答案。
Speed up AppleScript UI scripting?
希望这有帮助。
答案 1 :(得分:0)
点击或axpress似乎会造成很大的延迟。
相反 - 获取位置并使用第三方shell脚本进行单击。快得多。
使用clicclik:https://www.bluem.net/en/mac/cliclick/
放入用户库/应用程序支持/单击
set clickCommandPath to ((path to application support from user domain) as string) & "Click:cliclick"
set clickCommandPosix to POSIX path of clickCommandPath
tell application "System Events"
tell process "Pro Tools"
set frontmost to 1
tell button "Track List pop-up" of window 1
set {xPosition, yPosition} to position
set x to xPosition
set y to yPosition
end tell
do shell script quoted form of clickCommandPosix & " c:" & xPosition & "," & yPosition
key code 36 -- return key stroke
end tell
告诉