@Darrick Herwehe's answer has the crucial pointer: use oascompile
to compile AppleScript source code - no need for (cumbersome and error-prone) GUI scripting.
If you wanted to compile your AppleScript (plain-text) source file - e.g., some.applescript
to:
- application (bundle)
some.app
- with the execute-only (run-only) option (i.e., the plain-text source code is NOT included in the bundle)
you'd run
osacompile -x -o some.app some.applescript
Alternatively, you can even provide the source code as a _string:
osacompile -x -o some.app -e 'display alert "hello, world"'
If you wanted to achieve the same thing from AppleScript itself:
set src to "display alert \"hello, world\""
do shell script "osacompile -x -o ~/some.app -e " & quoted form of src
Note that the output format - an application bundle in this case - is inferred from the filename extension of the output filename passed to -o
.
To invoke some.app
directly from its output folder for a quick test, use:
open ./some.app
Caveat: There's at least 1 bug (around since at least 2012 and still there in OS X 10.9.2) that causes osacompile
to compile incorrectly; see osacompile changing the AppleScript output so it won't run