|
|
|

|
Opening a Compiled Script as Text
|
|
Sometimes, AppleScript prevents Script Debugger from opening a compiled script file, or shows the file’s contents with raw Apple event codes. This indicates that something has gone wrong with the decompilation process. For example, an application or scripting addition needed by the script is missing, or a script’s internal alias to an application has broken.
If the script was originally saved with Script Debugger, you can open the script as text. To do so:
- Choose File > Recover Script.
This feature works because when Script Debugger saves a compiled script, it saves not only the compiled bytecode but also the uncompiled text. The uncompiled text is placed in the file’s resource fork (or, if the file is a bundle, in a file within the bundle).
Warning: You can accidentally strip away a compiled script’s resource fork. You might, for example, save the compiled script file on a non-HFS filing system (true Unix, or Windows), or send it through email without compressing it, or open it with some badly behaved script editor application. Also, if you edit a script with some other script editor application, the stored uncompiled text may no longer match the current state of the bytecode. If that happens, the original text is gone, and if there is then a problem with opening the compiled script file, this feature won’t work (Script Debugger won’t be able to recover the original text).
Script Debugger will automatically offer to let you take advantage of this feature, under two circumstances:
If you attempt to open a compiled script that targets an application which must be launched in order for AppleScript to decompile it. For example, suppose BBEdit is not running and you open a compiled script that targets BBEdit. BBEdit has a dynamic dictionary, so AppleScript wants to launch it in order to display the script. Script Debugger detects this and can optionally intervene, presenting this dialog:
You can proceed to open the script (and allow BBEdit to launch) if you wish, but perhaps the overhead of launching an application just to read a script seems unwarranted. If this script was saved with Script Debugger, it contains a text version, and you can click Open As Text to open that instead. Thus you can read the script without launching BBEdit. (But to compile the script you will have to let AppleScript launch BBEdit.)
If the script does not contain a text version, the Open As Text button will not be present.
If you attempt to open a compiled script that targets a missing application. In this case, on Mac OS X 10.4 (Tiger) and earlier, after you cancel out of the AppleScript “Where is…?” dialog, Script Debugger will offer you a chance to open the script’s text version, if it has one:
(This won’t happen on Mac OS X 10.5 and later because, there, when you cancel out of the “Where is…?” dialog, AppleScript opens the script anyway, displaying raw Apple event codes if necessary.)
Explore | Edit |
Run & Debug | Deploy | What's New In 4.5 |
My SD Story
|