AppleScript Editor record doesn't work

never_had_a_name picture never_had_a_name · Aug 22, 2010 · Viewed 16.8k times · Source

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?

Answer

Digital Trauma picture Digital Trauma · Sep 12, 2013

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:

![enter image description here

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

enter image description here

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.