Reading AppleScript source code with osadecompile
When working with AppleScripts that other folks have written, it’s often useful to be able to look at the source of the AppleScript. One quick way to do this via the command line is to use the osadecompile command. This command is designed to output the source of a compiled AppleScript or other OSA language scripts to standard output. For more details, see below the jump.
As an example of this, let’s look at an AppleScript which has been compiled into an AppleScript application. The application has the following source code and is designed to produce a dialog box reading Hello World.
The AppleScript in this case is named Hello World.app and it’s been saved into ~/Documents:
To read out the source code for the AppleScript application without opening a script editor, you can run the following command:
osadecompile /Users/username/Documents/Hello\ World.app
osadecompile will then display the source for the AppleScript application.
One thing to be aware of is that osadecompile is not able to display source for a read-only AppleScript script or application.
This is because a read-only AppleScript has had its source code stripped as part of the compiling process. With the source code removed, it cannot later be decompiled by either the Script Editor application or osadecompile.
In this case, osadecompile will display an error similar to the one shown below.