是AppleScript的UI脚本一般很慢,或者是我的剧本,还是其他什么东西? [英] Is AppleScript UI Scripting very slow in general, or is it my script, or something else?

查看:392
本文介绍了是AppleScript的UI脚本一般很慢,或者是我的剧本,还是其他什么东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来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的暂停点击图标并且执行第一键击,对,这是不切实际的作为脚本的点之间的时间长。下面是具有第一点击一跌preSS的版本。

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

难道这是我的code的一个问题?如果设置的地方? 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秒后脚本回报,但我无法弄清楚如何在不延迟运行后,一键code命令。

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脚本一般很慢,或者是我的剧本,还是其他什么东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆