[OS X] How do I create a bundle "file" ?


As far as I understand, under OS X, a bundle file is a Folder with “special” extension.

I was thinking to use that feature, but I failed to find documentation on how to create such 'file’…

All ideas are welcome.

I don’t know the exact specs, but a bundle isn’t simply a folder with a specific extension. It requires a specific hierarchy [quote]A package is any directory that the Finder presents to the user as if it were a single file.
A bundle is a directory with a standardized hierarchical structure that holds executable code and the resources used by that code.[/quote]

I took that from the following link, which may be helpful:

More specifically, you should look at DocumentPackages :slight_smile:

Your app simply creates a folder.
The bundle thing comes from entries in your app’s info.plist.

Document Packages are easier than you think and you can start by simply creating a folder, giving it an extension and stuffing your data into that folder.

Download the free trial of Shine , throw in a photo and save the document, then right click on it and select “Show Package” contents.

The complicated part comes from editing your plist to make the OS recognize the folder as a document. This requires that your app’s plist be edited outside of Xojo. Both App Wrapper and App Wrapper Mini have provision for this.

If you want to do it manually, you need to add “LSTypeIsPackage” (with the value of “YES”) to the document type in the “CFBundleDocumentTypes” section of the plist. Take at a look at Shine’s plist to see an example.

Once you’ve got it working, you can get into some cooler stuff.

if you add a info.plist file to your document package, you can alter the properties in the get info window, again Shine does this (it also stores the document data in the plist file).

You can use Marc’s trick of including a “QuickLook” folder within the package allowing people to QuickLook at your document.

In Shine, when you save the document, we store the original image within the package, so if the user wants their original photo back, it’s there!

You can provide your own incremental backup system within the bundle (again Shine does this).

I choose to add an extra file, because if the package is on a computer without the app, it appears as a regular folder, I placed the extra file “Shine Document.txt” to help the user identify where this package came from (although I could have done a better job).

[quote=42240:@Mark Walsh]I don’t know the exact specs, but a bundle isn’t simply a folder with a specific extension. It requires a specific hierarchy

I took that from the following link, which may be helpful:
Ah… Yes I just re-read your message and there is a difference between a bundle and a document package. The key element I can think of is that a bundle contains some form of executable code and a bundle will always appear to the user as a single file.

A document package is much lighter and designed for purely data, if the app that created the docPac is not on the system, it will show up as a regular folder.

Thank you all for the answers.

It seems to me that I was wrong (bundle), a document package looks like what I really need.

I want to put in a “container” a bunch of data my application will read. I actually use a folder to keep together data (tons of folders with 3 files each)…

Simply create a folder with the extension “.bundle”, put your files in this folder - that’s all. You can access your files with a normal FolderItem (MyFolder.bundle).

Thanks Horst.

May works OK if I change the bundle icon (fine), but a double click in the bundle runs the Terminal.

You know how users can be… And I may want to allow double-click to open the bundle with my application. Idea ?


And the bundle file have “.bundle” as ‘file’ extension.

It does not need that. Use your own :slight_smile:
Find your extension in your apps info.plist file and add:

This way the system knows that the folder with your extension is to be treated as a document package.

I’ll create a quick example for you :slight_smile:

Here’s an example I just created in about 5 min…so treat it as an EXAMPLE(almost pseudo code ;)) but it should be working or at least give you some ideas :slight_smile:

I personally wouldn’t advise in doing so, as bundle is a generic term and trying to associate bundle with your application, may potentially cause system issues as the system uses .bundle. Instead use your own file extension so that the files can be associated (double clicked) with your application.


that is (I think) what I want to do: put my application data into a master container.
[one master container for each subject: this is a multimedia project]

Ditto. I’m pretty sure that on my system, double clicking a .bundle file in Finder just digs into its contents.

I think your original question was “How do I create a package Folder on the Mac?”

If that is true and you are a holder of the MBS PlugIns then the following code will do that for you:

[code] const kHasBundle = &h2000
dim fl as integer = f.GetFolderFlagsMBS

if fl < 0 then // failed
fl = kHasBundle
fl = BitwiseOr(fl, kHasBundle)
end if

dim e as integer = f.SetFolderFlagsMBS(fl)

if e = 0 then
Return True
Return False
end if
I use this to create my ‘folder’ that is a package folder and it shows as a ‘file’ in Finder. I can then add folders within and, of course, add the files that I need for my app to access. I create a special extension and associate that with my app.

1 Like


create a new folder, change its name to “my folder.bundle” (that is all, nothing was put inside the folder) and double click on it :

a. Change the icon from Folder to some kind of white Lego form artwork,
b. runs the terminal (and displays the bundle name

Mavericks / MacBook Pro

Of course, your milestone may vary (for unknown reasons).

Thanks Simon,

All I want is a way to place multimedia data in a convenient place (I actually use a master folder).

And, no, I do not have Christian’s plugins.