简体   繁体   中英

AppleScript Editor record doesn't work

I have opened the AppleScript Editor and pressed Record button.

Then I run TextEdit, create a file and put some text there.

When I click the Stop button in AppleScript Editor, nothing was recorded, the window is blank.

What is the problem?

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.

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:

![在此处输入图片说明

  • 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:

在此处输入图片说明

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 - eg 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.

The problem is that applications need to explicitly support AppleScript recording in order for it to work, but almost no applications actually do. Finder still supports it a bit, and maybe a couple other apps (BBEdit comes to mind), but for the most part, AppleScript recording has been pretty useless for quite some time.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM