You could try:
sudo -u $(ls -l /dev/console | awk '{print $3}') open /Applications/Appname.app
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.
$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.
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.
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
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'