For an application I recently worked on I needed to create an OS X installer that would automatically place an Excel macro in the default Microsoft Office Add-Ins directory. Using PackageMaker I decided to have the installer initially drop the macro in the /Users/Shared directory. Since the application is for an internal group of users I knew I could safely assume Microsoft Office is installed under /Applications and retains the default directory naming convention.

After some tinkering I ended up with the bash script below. I was quite pleased with myself :)


find /Applications -type d -maxdepth 1 -name "Microsoft Office*" 2>/dev/null | awk '{print "/Users/Shared/Sweet.xla"; print "\"" $0 "/Office/Add-Ins/Sweet.xla\""}' | xargs -n 2 cp
rm -f /Users/Shared/Sweet.xla
exit 0
  1. First I find all directories directly under /Applications that start with the name “Microsoft Office”. Any errors are redirected to /dev/null instead of standard out.
  2. The result of that is piped into awk to format two arguments, a source and a destination.
  3. Using xargs those two arguments are then passed into the cp command (-n 2 makes sure only 2 arguments are used)

Voila! The nifty part is that this will copy the macro into multiple versions of Office if they exist.