In order to version control my applescripts I started to save them as text ('applescript’). However to execute them it’s better to have them avaivble as binary script ('.scpt’).
Is there a command line tool I can use for this conversion? Or do i have to do it via Script Editor / Script Debugger?
The very best would be a background tool which watches the directory and converts changed applescript text files on the fly into binaries…
use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use framework "OSAKit"
use scripting additions
set theFile to (choose file of type {"applescript"})
set aURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of theFile)
set destinationURL to aURL's URLByDeletingPathExtension()'s URLByAppendingPathExtension:"scpt"
set {theScript, theError} to current application's OSAScript's alloc()'s initWithContentsOfURL:aURL |error|:(reference)
if theScript is missing value then error theError's |description|() as text
set {theResult, theError} to theScript's compileAndReturnError:(reference)
if theResult as boolean is false then return theError's |description|() as text
set {theResult, theError} to theScript's writeToURL:destinationURL ofType:"scpt" usingStorageOptions:0 |error|:(reference)
if theResult as boolean is false then return theError's |description|() as text