How to (de-)compile AppleScript with Scripting Definition from the command-line

I want to compile and de-compile AppleScript from the command-line, so I can put the text-files into git. However, I run into problems with a Scripting Library that contains sdef (Scripting Definition) files.

When I perform decompile MyLib.scptd/Contents/Resources/Scripts/main.scpt, I get output like:

use AppleScript version "2.4"
use scripting additions

on «event ABCDEFGH» my_argument
    --...
end «event ABCDEFGH»

which is fine i guess, since the raw commands («event ABCDEFGH») it the textual and runnable representation of the source code of the Scripting Library. (the event ABCDEFGH is obviously an example; I use other codes but for sake of simplicity…)

However, how do I compile this source back into a script library, I can’t get it to use my script definition file. osacompile doesn’t have an argument for an sdef-file. When I pass the sdef-file as a 2nd argument, osacompile complaints MyLib.sdef:1: error: A “<” can’t go here. (-2740).

Is it at all possible to do this I want from the command line, and if so, how?

Why don’t you save your original script as .applescript, put that in git and then compile ?

I don’t think so. It’s actually a reasonably tricky thing to do anywhere.

I think I lost my mind. There never was a problem, except from me having to many assumptions.

I’m just back from holiday, and now it’s obvious.

@suzume is right. A script bundle with scripting definition is no different than one without one. The scpt-file contains raw-codes when an SDEF (Scripting Definition) is being used. Just decompile the scpt-file when putting into git, and compile back to scpt when getting out of git.

@ShaneStanley: I think you are refering to putting the SDEF values into the the git-difff? Like what an editor like Scripting Debugger is doing. That would be pretty reasonably tricky indeed.

Thanks for looking into my non-issue :wink:

1 Like

No, the challenge comes if you are trying to compile without the raw codes.

Yeah, I can imagine.