Skip to main content
Question

Scripting a file from within a, application container


rpayne
Forum|alt.badge.img+11

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

Forum|alt.badge.img+16
  • Valued Contributor
  • 1002 replies
  • May 31, 2017

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
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7881 replies
  • May 31, 2017

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
Forum|alt.badge.img+11
  • Author
  • Contributor
  • 124 replies
  • June 1, 2017

@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
Forum|alt.badge.img+11
  • Author
  • Contributor
  • 124 replies
  • June 1, 2017

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
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7881 replies
  • June 1, 2017

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
Forum|alt.badge.img+11
  • Author
  • Contributor
  • 124 replies
  • June 1, 2017

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
Forum|alt.badge.img+36
  • Legendary Contributor
  • 4293 replies
  • June 1, 2017

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings