February 23, 2010

osadecompile and high level ASCII characters

Filed under: General Information — Ryan Wilcox @ 1:46 pm

If you have a batch of Applescript .scpt files to convert into text, do NOT use the command line osadecompile tool.

You use this tool like so:

$ osadecompile myscript.scpt > myscript.applescript

If your .scpt has high ASCII characters in it (like Applescript’s line break character, the Ã?¬) the .applescript file you get out will not have your high level ASCII line break. Which breaks the script if you turn around and try to run it in Script Editor.

Which is bad. I’m not sure why this happens, but I have some theories (osadecompile is broken in respect to high ASCII characters, or unix piping is to blame. I hold both these theories to be equally possible).

I’ve decided to use Script Editor itself to decompile the .scpt and write the file a .applescript file. (Which is cool that this works – in fact you can have Script Editor running my conversion script while opening up windows in it to do the save as. Good job, Apple!)

The most essential part of the script is as follows:


save d as "script" in POSIX file (((destinationFolder & theName as string) & "scpt") as string) with run only

Download the full script here