Scripting a file from within a, application container

Contributor II

I'm attempting to create a script to run a file that is housed within an application container. I will fully admit that scripting and me are not friends. Suggestions?


Valued Contributor III

As long as it's an executable you can just call it directly.


You might need to be more specific as to what you are trying to do?

Legendary Contributor III

Can you expand on what you're trying to do here? I'm not understanding what you mean by "create a script to run a file that is housed within an application container" Do you mean you want the script to launch something from within an application bundle?

Contributor II

@mm2270 I'm attempting to run an application (clamxav sentry) that is housed inside the ClamXav app container. I'm just not familiar enough with bash/shell. I can do it in Apple script with:

tell application "Finder" activate open application file "ClamXav" of folder "Resources" of folder "Contents" of application file "" of folder "Applications" of startup disk
end tell

Contributor II

Calling on it directly delivers the following error. It seems that it doesn't like the space (/Applications/

[STEP 1 of 4]
Executing Policy TEST Sentry script
[STEP 2 of 4]
Running script TEST SENTRY...
Script exit code: 127
Script result: /Library/Application Support/JAMF/tmp/TEST SENTRY: line 2: /Applications/ No such file or directory<br/>
Error running script: return code was 127.

Legendary Contributor III

In bash you need to either escape spaces with a backslash /Applications/ or place double quotes around the entire path that contains spaces. "/Applications/"

However, i should mention there's a 50/50 chance of this not working, depending on how the policy is being called. If it's running during a check in trigger that runs entirely as root, and will likely fail since the OS won't allow it to open apps in the user context. If it's running from a Self Service policy there's a slightly better chance it will work, but it still might fail. Getting policies run from Casper to run as the user is one of the tricky things that literally everyone has run across and there are a few different methods to do it.

Contributor II

I got it working. I'm an idiot:

using the following did the job.


open /Applications/

Esteemed Contributor III

@rpayne bear in mind if you're scripting this, the script must open as the current user.