AppleScript_ The Definitive Guide - Matt Neuburg [36]
"echo 'hi'" password "myPassword"
The reason is that the bytecode contains no information about whitespace, so the new formatting imposed by the decompilation process may not correspond to your original whitespace. This looks like a trivial annoyance, but if the line were longer it wouldn't be so trivial. Fortunately, the current version of the Script Editor wraps long lines, so the problem is far less disruptive than it was in the past because there isn't much need to use the continuation character any more.
(Some more examples of this odd behavior of AppleScript's will appear in "Abbreviations and Synonyms" in Chapter 5 and elsewhere, including "Variable Names" in Chapter 7.)
Compiled Script Files
A compiled script file is just what you think it is: it's a file containing the bytecode of a compiled script. Unlike text, a compiled script file can be executed without being compiled (because it's already compiled); the runtime engine is fed the bytecode and can leap into action immediately. A lengthy script can take several seconds to compile, so a compiled script file clearly saves some time and overhead when the script is executed. Obviously this architecture is advantageous when the script is not going to change and therefore will not need compiling ever again—when you distribute the script to others, for example. Applications that act as script runners typically operate on compiled script files (see "Script Runner" in Chapter 2). Script editor applications save a script as a compiled script file by default. When an application has asked the AppleScript scripting component to compile some text, a compiled script file is the only way for the compiled script to outlive that instance of the AppleScript scripting component, which will go out of existence when the host application quits.
(There is actually more to a script, and therefore there can be more to a compiled script file, than the compiled bytecode. I'll discuss these further contents of a compiled script file in "Persistence of Top-Level Entities" in Chapter 8 and "Closures and Stored Script Objects" in Chapter 10.)
You cannot save as a compiled script file code that, for whatever reason, will not compile. This seems tautological, but it can be surprising nevertheless, so it is worth mentioning.
Compiled Script File Formats
To make things more complicated, a compiled script file can come in not one, not two, but three different formats :
Resource-fork file
The bytecode is kept in the file's resource fork ; there is no data fork . The type is 'osas'; the extension is .scpt. Historically, this is the oldest form. Script Editor will not create a file in this form (though Script Debugger can), but if Script Editor encounters such a file it can open, edit, and save it in the same form.
Data-fork file
The bytecode is kept in the file's data fork. (There may be a resource fork, but it's for other things, such as the script's description and window state.) The type is 'osas'; the extension is .scpt. This is the default form created by Script Editor, where it is called simply "script"; Script Debugger calls it "Compiled Script (Data Fork)."
Script Bundle
The bytecode is kept in the data fork of a file called main.scpt, which has no resource fork and lives inside the Contents/Resources/Scripts folder of a bundle . (A bundle is a folder that is presented through the graphical user interface as a file.) Other information is stored in the data fork of other files in the bundle; the description, if any, lives in a file called description.rtfd, and window state is stored in the bundle's Info.plist. The bundle can be used to hold further ancillary resources (an example appears in Chapter 25). Script Editor calls this format "script bundle "; Script Debugger calls it "Compiled Script (Bundle)."
Originally there was just one compiled script format—the resource-fork file . Life was simple: any context that might open a compiled script file in order to run it (technically known as loading the script) could be relied upon to deal with any compiled