How to make compiled applescripts on $PATH be found and executed

applescript

I have some short applescripts that I want to use as utility functions inside shell scripts– for example, one returns the name of the frontmost application. The scripts reside in a personal scripts directory that is on my $path. When in another directory, I can just run

$myscript.applescript

And, because the scripts directory is on the path, this file will be found and executed (at the top is #!/usr/bin/env osascript). However, when I run

$myscript.scpt

To try and run the compiled version, I get:

zsh: exec format error: get_front_app_name.scpt

I would like to use the compiled version but would also like to be able to run these like any executable on my $path, that is, without having to specify the interpreter name (osacompile) or the path to the file. As of now, the only way I can see to execute the compiled .scpt applescript is to do both:

$osascript path/to/myscript.scpt

Is it possible to run the compiled form without this baggage?

Best Answer

Since .scpt are not executable you won't be able to do this.

The shebang (!#) is not in the AppleScript syntax and therefore it won't do anything.