Sunday, August 10, 2025

macos – How to osacompile a script containing `tell Application` and NSAppleScriptEnabled without activating it

How do I compile the following script without actually activating the application during the compilation?

tell application "/Applications/VLC.app" to activate

If I do e.g. this, it will not only create a launcher bundle, but also activate VLC.app during compilation:

osacompile  -o foo.app -e 'tell application "/Applications/VLC.app" to activate'

This launches VLC immediately, even if you don’t touch foo.app.

I played around with the Info.plist in VLC.app and I found that the offending flag is this one:

    <key>NSAppleScriptEnabled</key>
    <true/>

If the target app bundle specifies that, it will launch on compilation. I can only assume osacompile does some kind of inspection on the bundle, sees that flag, then somehow has to activate the app to inspect its applescript support?

VLC is just a place holder here, I’m trying to programmatically create launchers for arbitrary applications. My current work-around is do shell script "open \"/Applications/VLC.app\"". It works for activating (the run hook), but not for other hooks, e.g.

on open names
  tell application ... to open names
end open

That also opens the target app on compilation if it declares support for apple script.

My question is: how do I avoid that, and just create a pure launcher script without osacompile actually launching the app?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles