2

Consider the following AppleScript program:

tell the application "TextEdit" to make new document

I saved this script as an Application, and ran it successfully by double-clicking the application icon.

I then simplified the script by setting the 'tell current application' popup menu to 'TextEdit' and replacing the program with the following line:

make new document

Simplified AppleScript program

I saved the script and ran it from within Script Editor. Everything worked OK. I then ran the application by double-clicking the application icon, but now the following error message appeared:

Can't make class document
Can't make class document. (-2710)

Can't make class document error message

What is the reason for this behavior?

1

You cannot create an AppleScript application that only contains the single line of code make new document as it will not execute within the same context it does in Script Editor having made a selection from the "tell" application menu.

As an AppleScript application you need to explicitly tell the appropriate application to make new document.

Example: tell application TextEdit to make new document

If you only code make new document and save it as, e.g. Code Test.app then make new document executes as tell current application to make new document or more literally in this case, tell application "Code Test" to make new document and the Code Test.app lacks the ability to create a new document and therefore errors out.

While in Script Editor, the "tell" application menu is a handy shortcut to avoid fully typing out tell application ... and is only for testing code. It is not translated to the literal code that you must be fully type so as to be fully functional within proper context to save as an application (or script for that matter).

  • Thanks. I find it to be a poor GUI design choice. In my opinion the behavior should have carried over to the application. – Evan Aad Apr 17 '17 at 6:59
  • 1
    @Evan Aad, I agree Script Editor is not well designed and lacks many features present in other Programing IDE's however the AppleScript Language Guide lays the foundation for how to write the code properly, regardless of what editor is used. – user3439894 Apr 17 '17 at 7:13
  • What other IDEs are available for AppleScript? Are there any that you would recommend? – Evan Aad Apr 17 '17 at 7:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .