AppleScript UI Scripting 通常很慢,还是我的脚本,或其他什么? [英] Is AppleScript UI Scripting very slow in general, or is it my script, or something else?
问题描述
我是 AppleScript 的新手,刚开始研究 UI 脚本.我正在尝试为程序 TypeIt4Me 创建一个脚本,这是一个不支持 AppleScript 的菜单栏实用程序(文本扩展).
I'm new to AppleScript, and am just diving into UI Scripting. I'm attempting to create a script for the program TypeIt4Me, which is a menu bar utility (text expansion) that has no AppleScript support.
我提议的脚本将利用系统事件单击其菜单栏图标,键入五次,一次,然后返回.但是,AppleScript 在单击图标和执行第一次击键之间会暂停很长时间,以至于这作为脚本是不切实际的.下面是第一次点击和一次按下的版本.
My proposed script would utilize System Events to click its menu bar icon, type down five times, right once, and Return. However, AppleScript pauses for a long time between clicking the icon and performing the first keystroke, to the point that this is impractical as a script. Below is the version that has the first click and one down press.
tell application "System Events"
click menu bar item 1 of menu bar 2 of application process "TypeIt4Me"
key code 125 -- ie "down"
end tell
这可能是我的代码有问题吗?某个地方的设置?AppleScript 一般?谢谢.
Could this be a problem with my code? A setting somewhere? AppleScript in general? Thanks.
推荐答案
你的脚本对我来说也需要大约 5 秒才能运行.不过,这种延迟并不常见.
Your script also takes about 5 seconds to run for me. Delays like that are not very common though.
这使得脚本在大约 0.05 秒后返回,但我无法弄清楚如何在没有延迟的情况下运行关键代码命令.
This made the script return after about 0.05 seconds, but I couldn't figure out how to run a key code command after it without the delay.
ignoring application responses
tell application "System Events" to tell process "TypeIt4Me"
click menu bar item 1 of menu bar 2
end tell
end ignoring
这也不起作用:
with timeout of 0.2 seconds
try
tell application "System Events" to tell process "TypeIt4Me"
click menu bar item 1 of menu bar 2
end tell
end try
end timeout
tell application "System Events"
key code 125
end tell
在命令之间终止系统事件确实有效:
Terminating System Events between the commands did work though:
ignoring application responses
tell application "System Events" to tell process "TypeIt4Me"
click menu bar item 1 of menu bar 2
end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events"
key code 125
end tell
这篇关于AppleScript UI Scripting 通常很慢,还是我的脚本,或其他什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!