Bash’s osadecompile command is a principal tool used to retrieve the source text of a compiled AppleScript or ASObjC script. I recently discovered that osadecompile strips the mandatory pipes from the ASObjC keyword |description| in the returned source text. In contrast, the Script Editor and Script Debugger script editors preserve |description|'s pipes in their document windows and when saving the script back to disk.
By way of demonstration, save the following ASObjC script as a file named DemoFile.scpt at any arbitrary location on disk:
use framework "Foundation"
use scripting additions
property || : current application
set aliasFileURL to (||'s |NSURL|)'s fileURLWithPath:"/POSIX/path/to/any/Finder/alias/file"
set resolvedFileURL to (||'s |NSURL|)'s URLByResolvingAliasFileAtURL:aliasFileURL options:0 |error|:(missing value)
set fileDescription to resolvedFileURL's |description|()
display dialog (fileDescription as text)
The example was chosen because it contains various forms of piped names. Open the saved DemoFile.scpt file in Script Editor or Script Debugger. The pipes are preserved in all piped names, including the |description| method name.
Now apply the osadecompile command to the saved DemoFile.scpt file. The |description| method name’s pipes are now stripped:
do shell script "osadecompile " & ([/POSIX/path/to/DemoFile.scpt])'s quoted form
--> strips the pipes from the description method name: ...set fileDescription to resolvedFileURL's description()...
When DemoFile.scpt is run as a script from the source text opened in the Script Editor or Script Debugger document window with |description|'s pipes preserved, the script executes properly:
run script "use framework \"Foundation\"
use scripting additions
property || : current application
set aliasFileURL to (||'s |NSURL|)'s fileURLWithPath:\"/POSIX/path/to/any/Finder/alias/file\"
set resolvedFileURL to (||'s |NSURL|)'s URLByResolvingAliasFileAtURL:aliasFileURL options:0 |error|:(missing value)
set fileDescription to resolvedFileURL's |description|()
display dialog (fileDescription as text)"
--> displays the description of an NSURL object of the underlying file of a Finder alias file, if a valid alias file POSIX path was supplied for /POSIX/path/to/any/Finder/alias/file
In contrast, when DemoFile.scpt is run as a script from the source text returned by osadecompile with |description|'s pipes stripped, the script fails:
run script "use framework \"Foundation\"
use scripting additions
property || : current application
set aliasFileURL to (||'s |NSURL|)'s fileURLWithPath:\"/POSIX/path/to/any/Finder/alias/file\"
set resolvedFileURL to (||'s |NSURL|)'s URLByResolvingAliasFileAtURL:aliasFileURL options:0 |error|:(missing value)
set fileDescription to resolvedFileURL's description()
display dialog (fileDescription as text)"
--> fails with an error because of the missing pipes in the description method name
This is the only case I’ve encountered over the years where osadecompile returns source text different from the form in which the script was originally saved, and in this case sufficiently different that it causes the script to fail when run from the source text. It raises the questions: Why does osadecompile strip only |description|'s pipes but not those of any other names (at least that I’m aware of)? Should this be considered a bug?