OSACOMPILE_EXECUTE_ONLY does not make script execute only

I have an Apple Script added to my project and copying it to bundle resources. I have set OSACOMPILEEXECUTEONLY to yes under Build Settings. I compile my project, open the Application bundle and reach to myAppleScript.scpt under Resources folder.
I am able to open myAppleScript.scpt in Script Editor and view its source.
As per documentation OSACOMPILEEXECUTEONLY should make it executable and cannot view the original source in Script Editor.
Do you see the same problem if you compile the script with osacompile with the -x flag?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I am facing the same problem if I run osacompile with -x flag. osacompile -x <MyAppleScriptPath>.
If I open Apple Script at path MyAppleScript
Path after running osacompile command, I can still read Apple script command whereas the expectation is the script will be in executable format and command are not readable.

This is working for me with osacompile. I’m working on macOS 11.1:

Code Block
% sw_vers
ProductName: macOS
ProductVersion: 11.1
BuildVersion: 20C69


I created a trivial script:

Code Block
% cat beep.applescript
beep


I then compiled it:

Code Block
% osacompile -x -o beep.scpt beep.applescript


Running it using osascript works:

Code Block
% osascript beep.scpt


Opening it with Script Editor:

Code Block
% open beep.scpt


displays the alert:

The document “beep.scpt” could
not be opened.

Unable to read the file because the
script is not editable (it was saved as
run-only).

[[OK]]

What version of macOS are you testing this on?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thank you eskimo. The usage of the command was not proper. Now, it worked for me.
I had used initially:
osacompile -x <MyAppleScriptPath.scpt>
It should have been osacompile -x -o <MyAppleScriptReadOnlyPath.scpt> <MyAppleScriptPath.scpt>

But, why it does not work via XCode Build Settings?

But, why it does not work via Xcode Build Settings?

This is working for me. Here’s what I did:
  1. I created a new Mac app using Xcode 12.4.

  2. I added a beep.applescript file to it.

  3. Using the Build Settings editor, I set Save as Execute-Only (OSACOMPILE_EXECUTE_ONLY) on the app target.

  4. I built the app.

The resulting app contains a beep.scpt that’s execute only.

When I look in the build transcript I see this:

Code Block
OSACompile /Users/quinn/Desktop/Test672579/Test672579/beep.applescript (in target 'Test672579' from project 'Test672579')
cd /Users/quinn/Desktop/Test672579
/usr/bin/osacompile -l AppleScript -d \
-o …/Build/Products/Debug/Test672579.app/Contents/Resources/beep.scpt \
-x \
/Users/quinn/Desktop/Test672579/Test672579/beep.applescript


Note the presence of the -x flag.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I have attached the sample project that I created to learn OSACOMPILEEXECUTEONLY. I have added apple script "ScriptTest.scpt" to the project, OSACOMPILEEXECUTEONLY is set to true. If I compile the project and check the Resources folder of the TestScript.app, there exist ScriptTest.scpt which can be opened and readable in ScriptEditor.
Would you please let me know what I am doing wrong here.
The sample project is attached to your email … with the subject "OSACOMPILEEXECUTEONLY does not make script execute only"

I have added apple script ScriptTest.scpt to the project

That won’t work. A .scpt file is already compiled, so Xcode just copies it across to your app. This doesn’t invoke osacompile so there’s no opportunity for the -x flag to come into play.

The solution is to create an .applescript file with your source code. This is a text file, which will be compiled when you build your app, and that compilation will have the -x flag set.

ps Please don’t post my email address verbatim. I get enough spam as it is. I’ve edited your post to remove it (I’m generally reluctant to edit other people’s posts but I can and will do it where necessary).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thank you eskimo. This has worked for me.
Sorry for mentioning your email address.

Regards,
Deepa
OSACOMPILE_EXECUTE_ONLY does not make script execute only
 
 
Q