Print AppleScript files with color-coding in the Terminal

Posted on March 3, 2010
Filed under Mac, Programming, Scripts

asprint image Even though I curse and hate its syntax, I have to admit that AppleScript certainly provides one of the nicest things OS X has to offer in comparison to other operating systems: almost-ubiquitous scripting of GUI applications (one could argue that this is not due to the AppleScript language itself, but the Open Scripting Architecture which AppleScript is simply a language for, but that’s just semantics). Recently I’ve had to work with AppleScript files a bit more than usual while implementing Tagger‘s front app scripts feature, and I noticed that I often wanted to print out the contents of (compiled) AppleScript files in the Terminal. The built-in command osadecompile does just that: it reads in the AppleScript file, decompiles it, formats the code and nicely prints it out. I’m used to seeing my code with syntax highlighting, though, so I decided to write a small program that works similarly to osadecompile but uses ANSI escape sequences to format the output.

The Application Kit additions to the NSAppleScript class provide an implementation of the syntax highlighting (which would be the hardest part in implementing something like this) and I already have the ANSIEscapeHelper class that provides the translation of an NSAttributedString to an ANSI-escaped NSString (which would be the second-hardest part in implementing something like this) so writing a command-line program around these two parts was quite simple in the end. The program is called asprint and it has its own page on this site where you can download it.

This is what using asprint looks like:

asprint screenshot

Comments

4 Responses to “Print AppleScript files with color-coding in the Terminal”

Show/hide comments & reply form: