Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I flag a folder as being a package?

Tags:

cocoa

I used to think that folders needed to have an extension so that they are recognized as packages by the Finder. That extension would be declared in the owning application's Info.plist.

Obviously there is another, more elegant way, but I can't figure out how it is done.

E.g. the iPhoto Library is being treated as a package by the Finder. Yet it has no extension. mdls reveals that it indeed has "com.apple.package" in the content type tree. The actual content type is dynamically assigned.

How did iPhoto go about to create such a directory?

like image 257
Pierre Bernard Avatar asked Nov 18 '09 14:11

Pierre Bernard


People also ask

What is package directory?

The package Directories provides operations for manipulating files and directories, and their names.


1 Answers

Although you should not rely solely upon it, one thing to do is set the file's bundle bit. I've got a category on NSWorkspace to do just that:

- (void)setBundleBit:(BOOL)flag forFile:(NSString *)path
{
    FSRef fileRef;
    OSErr error = FSPathMakeRef((UInt8 *)[path fileSystemRepresentation], &fileRef, NULL);

    // Get the file's current info
    FSCatalogInfo fileInfo;
    if (!error)
    {
        error = FSGetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &fileInfo, NULL, NULL, NULL);
    }

    if (!error)
    {
        // Adjust the bundle bit
        FolderInfo *finderInfo = (FolderInfo *)fileInfo.finderInfo;
        if (flag) {
            finderInfo->finderFlags |= kHasBundle;
        }
        else {
            finderInfo->finderFlags &= ~kHasBundle;
        }

        // Set the altered flags of the file
        error = FSSetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &fileInfo);
    }

    if (error) {
        NSLog(@"OSError %i in -[NSWorkspace setBundleBit:forFile:]", error);
    }
}
like image 144
Mike Abdullah Avatar answered Nov 27 '22 11:11

Mike Abdullah