Wednesday, March 9, 2011

Using Mac OS X tools to manipulate the Info.Plist

There are several tools and ways to edit the property list, or plist, that's part of every Mac OS X bundle.

You might need to do this as part of getting your application ready for the Mac Application Store or because your application requires a newer version of Mac OS X than the default required by most Real Studio applications. Real Studio will, by default, set the entry for LSMinimumSystemVersion to 10.4 for Carbon apps or 10.5 for Cocoa applications.

If you have the Apple developer tools installed you can, as part of any build or run, use the Property List Editor in Developer > Applications > Utilities > Property List Editor to edit your plist. This is a nice GUI tool that Apple supplies that makes editing an applications plist very easy.
You can use this tool whether you are debugging or not by making use of Run Paused.
When you use Run Paused you can then locate the application, open the bundle and use the Apple Property List Editor to change/update whatever you need and then, when done, run the debug application and it will connect to the IDE that is waiting.

If you have an edition that supports Build Automation, you could script the change as a post build step using Apple's included Mac OS X tool called PlistBuddy located in /usr/libexec/PlistBuddy. (see http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/PlistBuddy.8.html)

As part of a post build step you could run a command like the following to set the minimum OS X version to 10.6.6. (This is only a sample to show you how it can be done.)

dim dbg as String
if debugBuild then dbg = ".debug"
dim appNameForShell as string
appNameForShell = PropertyValue("App.MacOSXAppName")+ dbg +".app" + "/Contents/Info.plist"
// there are several other special characters that you might need to escape
appNameForShell = replaceall(appNameForShell, " ", "\ ")
dim s as string
s = DoShellCommand("/usr/libexec/PlistBuddy -c ""Set :LSMinimumSystemVersion \""10.6.6\"" "" " + CurrentBuildLocation + "/" + appNameForShell )
print s

This saves you having to do this change in the Property List Editor manually every time.

Making it easier to adjust the plist is frequently requested but in the meantime you can use either of these mechanisms to update the property list generated by Real Studio.

5 comments:

Thomas said...

That code won't work if the path to the app contains spaces.

Norman said...

It works just fine here with the project located in
/Users/npalardy/Desktop/RB\ Test\ Projects/sample/untitled.rbp and the app being built is named My Application.
A debug run properly does NOT succeed as the app is limited to 10.6.6

Building the app using the Builds folder creates a bundled app in /Users/npalardy/Desktop/RB\ Test\ Projects/sample/Builds\ -\ untitled.rbp/Mac\ OS\ X\ \(Intel\)/My\ Application.app

Lots of spaces in my paths to these and they all work.

Thomas said...
This comment has been removed by the author.
Thomas said...

Oops, you're right. My bad. I had to add extra escaping only when I passed another file's plist to the tool. But that's an option you're not using.

Norman said...

There are other ways as well like
http://forums.realsoftware.com/viewtopic.php?f=7&t=37658&p=209490
which only requires a text editor and terminal