Sunday, September 13, 2009

Running an Application that requires a mounted Network Share

Here is an example of how to script the mounting of a network share, and launching an application.  You can then use a utility like Platypus to create an application.  In this case, the actual KIDPIX application folder is copied inside the application bundle created by Platypus.  This script mounts the share in the background and it does not appear in the finder.  It then waits for the program KIDPIX to quit and then unmounts the share.  Notice the $1/Contents/Resources which references the KIDPIX files located inside the application bundle.

_______ 8< snip ________


#!/bin/sh

echo "KIDPIX: Creating mount point"
mkdir /Volumes/KIDPIX4

echo "KIDPIX: mounting AFP server"
mount_afp -o nobrowse afp://username:password@server/KIDPIX4 /Volumes/KIDPIX4

echo "KIDPIX: Launching Application"
open "$1/Contents/Resources/Kid Pix 4 Network/Kid Pix Deluxe 4"

echo "Sleeping so Program can Launch"
sleep 10

echo "KIDPIX: Waiting for program exit"
while ps wwax | grep "[K]id Pix Deluxe 4" >/dev/null; do
sleep 5
done

echo "KIDPIX: umount volume"
umount /Volumes/KIDPIX4

echo "KIDPIX: Remove mount point"
rm -d /Volumes/KIDPIX4

echo "KIDPIX: Always exit 0"
exit 0