33

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?

Josh
  • 10,961
  • 11
  • 65
  • 108
never_had_a_name
  • 90,630
  • 105
  • 267
  • 383

3 Answers3

62

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.

Community
  • 1
  • 1
Digital Trauma
  • 15,475
  • 3
  • 51
  • 83
  • 2
    @Downvoter - what was wrong with this answer for you? It presents a different, more general approach to the other answers, which should help with the OP's problem. – Digital Trauma Apr 22 '17 at 21:22
  • I've been doing things with Automator for years and had no idea this feature existed - total lifesaver. Thank you! – SWL Jul 22 '18 at 04:18
  • You are my hero. I was trying to write the AppleScript from scratch and examples but having all sorts of validation issues, and the "example" scripts found in one of the folders from the Script Editor tray icon were horribly confusing. This got me much closer and I was able to apply the things I knew plus the recorded steps to successfully complete my task. – dragon788 Mar 28 '19 at 18:50
36

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.

Brian Webster
  • 11,915
  • 4
  • 44
  • 58
  • Isn't TextEdit Apple's own application? :) – never_had_a_name Aug 23 '10 at 01:39
  • 1
    Yes, TextEdit is Apple's own application, but their Applescript support has dwindled over the years. TextEdit's Applescript implementation leaves a lot to be desired. A lot of application support Applescript (more than you might think, actually), but it's more a case of the quality of the support is lacking than anything. If you need to script a text editor, you are much better off with BBEdit if you can get away with it. – Philip Regan Aug 23 '10 at 09:43
  • 1
    "The Finder still supports it a bit..." A lot of what was in the Finder is now found in System Events, and there is a lot more there than there ever was in the Finder. – Philip Regan Aug 23 '10 at 13:38
  • 9
    This is one of the great tragedies in Apple history. They could have allowed the basic set of events from the mouse and keyboard to be recordable in all apps, but for whatever reason they dropped the ball. We could have had users raised on the idea of recording macros to do their everyday tasks, but instead we've programmed humans to do the work that machines should be doing. – Zack Morris Mar 27 '15 at 19:42
  • Even Mail doesn't support it as far as I can tell. – Bill Apr 15 '18 at 20:10
3

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.

RyanWilcox
  • 13,890
  • 1
  • 36
  • 60