Script to open an app after install

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.


open /Applications/Utilities/

Rich Dagel
Senior Technology Specialist

Landor Associates
1001 Front Street
San Francisco, CA 94111
United States
415 365 3933
Rich.Dagel at



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> 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?



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

Valued Contributor

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



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

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

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.


USER=$3 # From Casper

su $USER -c "open /Applications/Utilities/"


su $USER -c "/Applications/Utilities/"

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
Ryan.Harter at

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?

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?


# Determine working directory


# 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

exit 0

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.