macos AppleScript 编辑器记录不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3542826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AppleScript Editor record doesn't work
提问by never_had_a_name
I have opened the AppleScript Editor and pressed Record button.
我打开了 AppleScript 编辑器并按下了录制按钮。
Then I run TextEdit, create a file and put some text there.
然后我运行 TextEdit,创建一个文件并将一些文本放在那里。
When I click the Stop button in AppleScript Editor, nothing was recorded, the window is blank.
当我在 AppleScript 编辑器中单击停止按钮时,没有记录任何内容,窗口是空白的。
What is the problem?
问题是什么?
回答by Digital Trauma
You can use the Record feature of the Automator to record the UI interaction steps needed to do the relevant workflow. Then you can then literally select and copy the recorded steps in automator and paste them into a new Applescript Editor window. This will give you applescript which may or may not work. You'll probably want/need to edit the resulting script, but at least it should help give an idea what is needed to achieve your workflow programatically. This method is usable regardless of whether or not the target application has an applescript dictionary or supports the AppleScript Editor Record button, as it is the interaction with the underlying UI elements which is recorded.
您可以使用 Automator 的 Record 功能来记录执行相关工作流所需的 UI 交互步骤。然后,您可以逐字选择并复制 automator 中记录的步骤,并将它们粘贴到新的 Applescript 编辑器窗口中。这将为您提供可能有效也可能无效的 applescript。您可能想要/需要编辑生成的脚本,但至少它应该有助于了解以编程方式实现工作流程所需的内容。无论目标应用程序是否具有 AppleScript 字典或是否支持 AppleScript Editor Record 按钮,此方法都可用,因为它记录的是与底层 UI 元素的交互。
Steps:
脚步:
- Open Automator
- Start a new "Workflow"
- Start recording
- Perform whatever steps you require with your app (in this case typing into textedit)
- Stop recording
- This will create a list of actions in Automator like:
- 打开自动机
- 开始一个新的“工作流程”
- 开始录音
- 使用您的应用程序执行您需要的任何步骤(在这种情况下输入 textedit)
- 停止录音
- 这将在 Automator 中创建一个操作列表,例如:
- Select all these and copy (CMD+c)
- Open the Applescript Editor app
- Paste (CMD+v). The result will be valid applescript to perform the actions you just recorded:
- 选择所有这些并复制(CMD+c)
- 打开 Applescript 编辑器应用
- 粘贴 ( CMD+v)。结果将是执行您刚刚记录的操作的有效applescript:
Note that as is generally the case with UI automation, the automator records steps exactly and the script plays them back exactly. This my not be exactly what you want - e.g. if a different application were active, the text could get typed in there instead. The generated applescript should be used as a guide to the final applescript.
请注意,与 UI 自动化的情况一样,自动化器会准确记录步骤,脚本会准确播放它们。这并不完全是您想要的 - 例如,如果不同的应用程序处于活动状态,则可以在那里输入文本。生成的applescript 应该用作最终applescript 的指南。
回答by Brian Webster
The problem is that applications need to explicitly support AppleScript recording in order for it to work, but almost no applications actually do. The Finder still supports it a bit, and maybe a couple other apps (BBEdit cones to mind), but for the most part, AppleScript recording has been pretty useless for quite some time.
问题是应用程序需要明确支持 AppleScript 录制才能使其工作,但实际上几乎没有应用程序支持。Finder 仍然有点支持它,也许还有其他几个应用程序(BBEdit 让人想起),但在大多数情况下,AppleScript 录制已经有一段时间没用了。
回答by RyanWilcox
Not all apps are recordable (in fact, only a small handful are). Recordablity is something each app needs to implement, and I guess TextEdit isn't recordable.
并非所有应用程序都是可录制的(实际上,只有少数应用程序是可录制的)。可记录性是每个应用程序都需要实现的东西,我猜 TextEdit 是不可记录的。