Open sesame

Here’s a simple little script that saves me a lot of time:

#!/bin/sh 

if [ -z "$1" ]; then
  echo "usage: $0 <app> [ Preferences | <document> ]"
else
  app=`ls -1td ~/Library/Application\ Support/iPhone\ Simulator/User/Applications/*/$1.app`
  dir=`dirname "$app"`
  if [ "$2" = "Preferences" ]; then
    open "$dir/Library/Preferences"
  else
    open "$dir/Documents/$2"
  fi
fi

Put this script somewhere on your PATH and name it opensim. Use it to find the most recent application loaded in the simulator and open the Preferences, Documents or a named document in the Finder.

For example, to open the current Documents folder for an application in the iPhone Simulator, just do this:

$ opensim Thunderbird

To open a document within that folder, you can do this:

$ opensim Thunderbird chockenberry.db
$ opensim Thunderbird accounts.plist

You can easily get to your preferences folder with:

$ opensim Thunderbird Preferences

Notice how I haven’t mentioned a GUID in this essay? That’s the feature…