Home > AppleScript, Mac administration, Mac OS X > Reading AppleScript source code with osadecompile

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.

Screen Shot 2016 05 10 at 7 40 50 AM

Screen Shot 2016 05 10 at 7 41 04 AM

 

The AppleScript in this case is named Hello World.app and it’s been saved into ~/Documents:

Screen Shot 2016 05 10 at 7 42 04 AM

Screen Shot 2016 05 10 at 7 44 04 AM

 

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.

Screen Shot 2016 05 10 at 7 57 13 AM

 

One thing to be aware of is that osadecompile is not able to display source for a read-only AppleScript script or application.

Screen Shot 2016 05 10 at 7 42 30 AM

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.

Screen Shot 2016 05 10 at 7 44 16 AM

In this case, osadecompile will display an error similar to the one shown below.

Screen Shot 2016 05 10 at 7 59 25 AM

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment