Script to open an app after install

rdagel
New Contributor II

I am trying to write a script that will open an app once it is installed by
a policy. I have to script set to run after but no luck.

#!/bin/sh

open /Applications/Utilities/MyApp.app

Rich Dagel
Senior Technology Specialist

Landor Associates
1001 Front Street
San Francisco, CA 94111
United States
415 365 3933
http://www.landor.com
Rich.Dagel at landor.com

6 REPLIES 6

talkingmoose
Moderator
Moderator

Is this policy set up to run as self-service or does it get triggered some
On 2/3/09 2:36 PM, "Dagel, Rich" <Rich.Dagel at landor.com> wrote:
other way?

Policies install under the root account, which means you're trying to open
it for a user who's not logged in.

What's the bigger picture of what you're trying to accomplish by opening an
application for a user just after install?

--

bill

William M. Smith, Technical Analyst
MCS IT
Merrill Communications, LLC
(651) 632-1492

milesleacy
Valued Contributor

I haven't tested this, it's just an idea off the top of my head...
Given:
Policies run as root.
An "open" command run as root won't open the item in another user's session
(I believe).

Try:

#!/bin/bash

if [ `who | grep -c "$3"` -gt 0 ] ; then su $3 open /Applications/Utilities/MyApp.app else echo "No user is logged in"
fi

Assuming I have my syntax right (and I'm not at a point in my day where I
can test this), this will test to see if $3 is logged in ($3 being the
username of the logged-in user as passed by Casper). If $3 is logged in,
the script will switch users to $3 from root, then run the open command.

----------
Miles A. Leacy IV

? Certified System Administrator 10.4
? Certified Technical Coordinator 10.5
? Certified Trainer
Certified Casper Administrator
----------
voice: 1-347-277-7321
miles.leacy at themacadmin.com
www.themacadmin.com

Not applicable

This is probably not a good idea (if it will even let you) since these scripts are run as root. If you do succeed in opening an app like that it will most likely open in the root context which is a really really really bad idea.

One thing you could try is su'ing as the user.

#!/bin/bash

USER=$3 # From Casper

su $USER -c "open /Applications/Utilities/MyApp.app"

or

su $USER -c "/Applications/Utilities/MyApp.app/Contents/MacOS/MyApp"

A lot of times open doesn't like being run from a script unless it is run from the current GUI user.

Ryan Harter
UW - Stevens Point
Workstation Developer
715.346.2716
Ryan.Harter at uwsp.edu

slundy
New Contributor III

Wanted to expand upon this. I used "Packages" to create an installer for Universal Type Client, so I could add a launchagent, and config file for the app.

Now I'm trying to find a way to, after the script that launches the installer, it then opens the app once it's done.

UTC installs fine on it's own so Packages may not be the best way to do this.

Any ideas?

slundy
New Contributor III

I've read that shell scripts will run each command sequentially, waiting for the previous command to finish before running the next.

so these commands should install the app, then when it's done, open it, correct?

#!/bin/sh

# Determine working directory

install_dir='dirname$0'

# Install Universal Type Client 6.1.7.pkg

/usr/bin/installer -dumplog -verbose -pkg $install_dir/"Universal Type Client 6.1.7.pkg" -target "$3"

# Open app after install

/usr/bin/open -a /Applications/Universal Type Client.app

exit 0

slundy
New Contributor III

Made a small change to the script, i changed #!/bin/bash to #!/bin/sh and it seems to have worked.

Installed, copied the prefs file, the launchagent, and then start the program up.