Scripting a file from within a, application container

rpayne
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?

7 REPLIES 7

Look
Valued Contributor III

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

#!/bin/bash
/Applications/TextEdit.app/Contents/MacOS/TextEdit

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

mm2270
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?

rpayne
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 Sentry.app" of folder "Resources" of folder "Contents" of application file "ClamXav.app" of folder "Applications" of startup disk
end tell

rpayne
Contributor II

Calling on it directly delivers the following error. It seems that it doesn't like the space (/Applications/ClamXav.app/Contents/Resources/ClamXav Sentry.app)

[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/ClamXav.app/Contents/Resources/ClamXav: No such file or directory<br/>
Error running script: return code was 127.

mm2270
Legendary Contributor III

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

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.

rpayne
Contributor II

I got it working. I'm an idiot:

using the following did the job.

!/bin/bash

open /Applications/ClamXav.app/Contents/Resources/ClamXav Sentry.app

donmontalvo
Esteemed Contributor III

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

--
https://donmontalvo.com