为什么AppleScript的总是以命令发送键击下来? [英] Why AppleScript always send keystrokes with Command down?

查看:145
本文介绍了为什么AppleScript的总是以命令发送键击下来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了很多这样的AppleScript的例子

I see a lot of examples of AppleScript like this

tell application "TextEdit"
    activate
    tell application "System Events"
        keystroke "s"
    end tell
end tell

预期的结果是字母s将在文本编辑(假设至少有一个文档窗口)被输入到活动文档。但相反,它总是试图保存的文件(这样做是为了更改的文档,打开保存对话框,如果它是一个新的)。同样的事情发生在任何应用程序的任何键,随时...

Expected result is that letter "s" will be typed into active document in TextEdit (assume there is at least one document window). But instead it always tries to save document (did it for changed document and open save dialog if it is a new). Same things happen for any key in any application at any time…

有谁知道为什么系统事件总是发送比如击键使用... {命令下}?

Does anybody know why System Events always send keystrokes like "… using {command down}"?

推荐答案

我使用Cmd的+ R,而不是通过点击运行按钮从AppleScript的编辑器中运行脚本。剧本开始后,我立即执行preSS键R来,那脚本发送按键S之前我释放Cmd的或R.这就是为什么与修改Cmd的发送键击S间$ P $点通过文本编辑。

I run script from AppleScript Editor using Cmd+R, not by clicking Run button. Script begins executing immediately after I press key "R" down and that script sends keystroke "S" before I release Cmd or R. That's why sent keystroke "S" interprets by TextEdit with modifier Cmd.

解决方法是单击按钮运行或脚本的开头增加延迟,按Cmd + R:

The workaround is to click button Run or add delay at the beginning of script and use Cmd+R:

delay 0.2 -- 0.2 second delay is enough

tell application "TextEdit"
    activate

这篇关于为什么AppleScript的总是以命令发送键击下来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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