Psellos
Life So Short, the Craft So Long to Learn

Wrap an iOS Simulator App as a Mac App

May 25, 2012

This note shows how to whip up a full-fledged Mac app that just launches an app in the iOS Simulator under Lion. It’s based on Platypus, a free program that wraps up any script as a Mac app. The wrapped script is essentially runsim, which runs an iOS Simulator app. See Run iOS Simulator from the Command Line (Improved) for the full description of runsim.

Until Apple releases the iOS Simulator as a standard part of OS X (which would open up all kinds of interesting possibilities for cross-device apps), the target audience for the generated apps is fairly small. Only an iOS developer is going to have the iOS Simulator readily available on their system. But, in fact, I often release iOS demo apps for other developers to look at, and anyway I think it’s pretty cool how easy it is to do this with Platypus.

One problem with running iOS Simulator apps automatically is that the location of the simulator isn’t the same on every system. The simulator is part of Xcode, which (under Lion) is an ordinary application that can be located anywhere you like.

To handle this, I use drag-and-drop: if you drop your Xcode.app onto the launcher app, it remembers the location for later. When you open the launcher app (double-click on it in the Finder), it uses the remembered location of Xcode to find the simulator. (The iOS Simulator app is literally located inside the Xcode app.)

So, the script to be wrapped by Platypus looks like this:

case $# in
0)
    ./runsim Psi ;;
*)
    case "$(basename "$1" | tr '[:upper:]' '[:lower:]')" in
    xcode.app) echo "$1" > runsim.xcloc ;;
    esac
    ;;
esac

When the wrapped script runs, it can tell whether it was a drag-and-drop target or not by the number of arguments. If there is no argument, nothing was dropped. The script just uses runsim to launch the desired simulator app. (In this example, it launches Psi, a tiny example iOS app.) If there is an argument, something was dropped. If it’s named Xcode.app, the script remembers its location for later.

I call this script clicksim. As given here, it needs to change a little bit depending on the iOS Simulator app you want to wrap up: you need to specify the name of your app after runsim.

That’s really all there is to it. Platypus handles the details of wrapping clicksim, runsim, the app executable, and any other associated files into a Mac app.

Platypus main window

The figure above shows how to configure Platypus to wrap clicksim and runsim. The bundled files are as follows:

  • Psi—the app executable
  • Icon.png—icon for the app in the simulator
  • runsim—the runsim script
  • runsim.uuid—UUID for the app
  • runsim.xcloc—location of Xcode

You can generate a UUID using the uuidgen utility. A good initial value for the location of Xcode is /Applications/Xcode.app. The runsim.xcloc file should be writable so that the script can change its contents if necessary.

To make the drag-and-drop facility work more nicely, you can specify the files that will be accepted by the app. Click the Settings button, and you’ll see a new dialog like this:

Platypus drag-and-drop dialog

In this example, we want to accept only files ending with .app (applications), and only folders (packages).

If you want to try this example yourself, I created an archive with all the parts you need. First, download Platypus from its home page, and install it. Then download the archive:

To try out the example from Finder:

  1. Double click the zipfile, then open the generated folder.
  2. Double click on FillProfile.app. This initializes paths in psilauncher.platypus for your site.
  3. Double click on psilauncher.platypus. This brings up the Platypus main window, as shown above.
  4. Click Create to create the app. Choose a convenient location for the generated app.
  5. Double-click on the PsiLauncher.app generated in step 4. This will start Psi in the iOS Simulator. It will be on the second page of apps—swipe to the left to see it.
  6. If Psi doesn’t show up, you may need to set the simulated iOS version. runsim puts apps into the iOS 5.1 simulator. Set the version number to 5.1 with the Hardware -> Version menu.

To try out the example from the command line:

$ unzip psi-platy-1.0.1.zip
$ cd psi-platy-1.0.1
$ fillprofile
$ platypus -P psilauncher.platypus PsiLauncher.app

To run PsiLauncher.app, you can double-click on it, or you can run it from the command line:

$ open PsiLauncher.app

As above, you may need to set the simulated iOS version to 5.1 for Psi to show up.

If you have any comments, corrections, or suggestions, leave them below or email me at jeffsco@psellos.com.

Posted by: Jeffrey

Comments

blog comments powered by Disqus