Question

I've been trying to program an AppleScript that writes and exports an AppleScript . And so far, I've gotten as far as automating the writing of the script and getting to the "Export..." menu. I've pasted link to a screen shot of the menu that I've gotten to below.

Link to image

can someone please let me know (in the simplest way possible) a way to automate the clicking of the Application option under the drop down menu (is it called that?) named File Format using apple script. Can someone also please inform me of (if there is) a way to automate the clicking of the Run Only check box? If you are unsure what is where, the two spots (the list and the check box) is squared in red in the image.

Was it helpful?

Solution

@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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top