Posted on 03-26-2012 11:07 AM
Hello, How do I have an app launched after it is installed by Casper remote without user interaction?
Running "open /path/to/app.app" or "sudo -u [shortname] open /path/to/app.app" in a pkg postflight.sh didn't work.
Running "sudo -u [shortname] open /path/to/app.app" from the advanced tab in Casper remote works sometimes, however running this command from a script does not.
Any help is appreciated.
Thank you!
Solved! Go to Solution.
Posted on 03-26-2012 11:36 AM
Try using the bsexec command with launchctl, typically this behavior is due to how the every* (i.e. every15) policies run (via launchd) and so you need to get out of that context. Either way this may help with Casper Remote as well.
#!/bin/bash
declare -x UserName="$(/usr/bin/who | /usr/bin/awk '/console/{print $1;exit}')"
echo "Derived Console username: $UserName"
declare -x LoginWindowPID="$(/bin/ps -axww | /usr/bin/grep loginwindo[w] | /usr/bin/awk '/console/{print $1;exit}')"
echo "Found PID: $LoginWindowPID"
/bin/launchctl bsexec "${LoginWindowPID:?}" /usr/bin/sudo -u "$UserName" /usr/bin/open /Applications/Calculator.app
https://gist.github.com/2210258
Just a note on @jarednichols comment, that should typically work as well, however be aware that is running the process as the root user if you omit the "open" and would block the procedural execution of your script until the app is complete. Leaving the open should not be much different then /Applications/Calculator.app , as in a way both basically execute the same process.
Posted on 03-26-2012 11:27 AM
Errors thrown?
Sometimes you need to go lower than the app bundle. e.g. open /Applications/Firefox.app/Contents/MacOS/firefox
Posted on 03-26-2012 11:36 AM
Try using the bsexec command with launchctl, typically this behavior is due to how the every* (i.e. every15) policies run (via launchd) and so you need to get out of that context. Either way this may help with Casper Remote as well.
#!/bin/bash
declare -x UserName="$(/usr/bin/who | /usr/bin/awk '/console/{print $1;exit}')"
echo "Derived Console username: $UserName"
declare -x LoginWindowPID="$(/bin/ps -axww | /usr/bin/grep loginwindo[w] | /usr/bin/awk '/console/{print $1;exit}')"
echo "Found PID: $LoginWindowPID"
/bin/launchctl bsexec "${LoginWindowPID:?}" /usr/bin/sudo -u "$UserName" /usr/bin/open /Applications/Calculator.app
https://gist.github.com/2210258
Just a note on @jarednichols comment, that should typically work as well, however be aware that is running the process as the root user if you omit the "open" and would block the procedural execution of your script until the app is complete. Leaving the open should not be much different then /Applications/Calculator.app , as in a way both basically execute the same process.
Posted on 03-26-2012 11:41 AM
You want:
open -a /path/to/app.app
Posted on 03-26-2012 11:57 AM
@talkingmoose
I have never used -a, like this, and I'm not sure it does anything different.
Typically its for the scenario when you want to open a specific file with a specific app
open /etc/resolv.conf -a /Applications/TextEdit.app
Both:
open /Applications/TextEdit.app
open -a /Applications/TextEdit.app
Do the same thing on my system, have you seen them act differently?
Posted on 03-26-2012 12:54 PM
Thanks acidprime! That code did the trick.
Posted on 03-26-2012 01:59 PM
Hey everyone,
I hope your weekends went well. As always it was too short. There are many ways to open apps via the command line. The open command itself has lots of switches because you can tell it to open a file in a specific application, which is why the -a switch exists.
Another option is a one liner apple secript:
osascript -e 'tell application "Safari" to activate'
Thanks,
Tom
Posted on 03-26-2012 02:23 PM
I can't be sure, but there may be an issue with doing this via Casper Remote. I tried using all of the above methods (open /path/to/application, open -a /path/to/application and osascript -e 'tell application "App Name" to activate') and they all fail with "An error of type -10810 has occurred. (-10810)"
Has anyone else seen this? This is when plugging these into the Advanced tab.
Oddly enough, SSH'd in, direct on the Mac in Terminal and via a policy (sudo jamf policy -trigger) all of the above work fine and launch the app. Strange! What is Casper Remote doing that is causing it to balk I wonder?
Posted on 03-26-2012 02:57 PM
Casper Remote is running under a local admin account on the remote machine. If the Finder is running under that local admin account then GUI applications should launch under the local admin account's login session.
However, sending a command using the remote machine's local admin account won't launch an application for "jcool" under his login session.