Posted on 10-31-2014 07:37 AM
When I install an app via Self Service, I like to put a line in the 'Files and Processes' section to open that App after its installed. I was using 'open /Applications/Utilities/thouleapps/MyGreatApp.app' However, That app launches, but can't request admin rights - I suspect because it was no launched by the current GUI user, but launched by Casper. If I quit the app, then launch via double-click, then it works great. I've also tried osascript yada yada with no success.
How do you guys open an application for the user via Casper?
Solved! Go to Solution.
Posted on 10-31-2014 07:40 AM
You could try:
sudo -u $(ls -l /dev/console | awk '{print $3}') open /Applications/Appname.app
Posted on 10-31-2014 07:40 AM
You could try:
sudo -u $(ls -l /dev/console | awk '{print $3}') open /Applications/Appname.app
Posted on 10-31-2014 07:44 AM
In your one line Files and Processes, do this
su Bob -c /Applications/Firefox.app/Contents/MacOS/Firefox
Make sure you drill down into the app. Since you can't technically launch the app from the .app part. So for instance, you wanted to launch the app for firefox, you drill down to the Firefox file that is the exec file.
In the spot of "Bob", you can do $2 i think, that will tell it to use the current user of self service.
Posted on 10-31-2014 07:58 AM
$3 is the current user, not $2.
I just set up a SS policy that had the following command in the Run Command field (still using JSS 8.73, but should be the same I would think under JSS 9.x) My Mac is running 10.9.5 BTW.
sudo -u $(ls -l /dev/console | awk '{print $3}') open /Applications/Casper Suite/Composer.app
And Composer opened just fine when running from Self Service for me. I got prompted to enter my own credentials for authentication. IOW, it was not opened as root, but as my account. There should be no need to drill down to the executable from what I can see.
You could substitute the ls -l /dev/console stuff with $3 and it should also work. i just prefer to get the logged in user my own way and not rely on the built in variables. But as I said, that should work as well.
Posted on 10-31-2014 10:48 AM
Looks like already been answered, but I've used this to open Applications:
#!/bin/bash
consoleuser=`ls -l /dev/console | cut -d " " -f4`
su - "${consoleuser}" -c 'open /path/to/application.app'
exit 0
I tend to prefer Scripts over using Execute Commands, though.
Posted on 03-06-2015 01:31 PM
I was seeing a Terminal window appear along with the application launch. If the Terminal is quit, the desired application quits as well. Running through AppleScript/osascript avoided this and may perhaps be more forgiving on the executable path.
#!/bin/bash
consoleuser=`ls -l /dev/console | cut -d " " -f4`
su - "${consoleuser}" -c 'osascript -e "tell application "*Safari*" to activate"'
exit 0
Posted on 07-15-2020 03:00 PM
For anyone trying this recently I had to make some adjustments to the above commands. This is what worked for me:
#!/bin/sh
su -l $(ls -l /dev/console | awk '{print $3}') -c 'open -a /Applications/AppName.app'