Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check whether directories with a given extension are shown by the Finder as a package?
    primarykey
    data
    text
    <p>For a given extension, how do you check whether directories with that extension will be shown by the Finder as a package?</p> <p>I figured the method below is an effective implementation for this, but creating a temporary directory feels like a hack. I'm guessing I should be able to implement this properly through the <a href="https://developer.apple.com/library/mac/#documentation/Carbon/Reference/LaunchServicesReference/Reference/reference.html" rel="nofollow">Launch Services API</a>, but I can't quite figure out how to do it (I might be overlooking the obvious though).</p> <pre><code>// Extension method on NSWorkspace @implementation NSWorkspace (MyExtraMethods) - (BOOL) isPackageExtension: (NSString*) extension { NSString * pathToTemp = [NSTemporaryDirectory() stringByAppendingPathComponent:[@"Untitled" stringByAppendingPathExtension: extension]]; [[NSFileManager defaultManager] createDirectoryAtPath:pathToTemp withIntermediateDirectories:NO attributes:nil error:NULL]; BOOL result = [[NSWorkspace sharedWorkspace] isFilePackageAtPath: pathToTemp]; [[NSFileManager defaultManager] removeItemAtPath:pathToTemp error:NULL]; return result; } @end // Basic test for the above - (void) testIsPackageExtension { STAssertFalse([[NSWorkspace sharedWorkspace] isPackageExtension: @"txt"], @""); STAssertFalse([[NSWorkspace sharedWorkspace] isPackageExtension: @"rtf"], @""); STAssertTrue([[NSWorkspace sharedWorkspace] isPackageExtension: @"rtfd"], @""); STAssertTrue([[NSWorkspace sharedWorkspace] isPackageExtension: @"app"], @""); STAssertTrue([[NSWorkspace sharedWorkspace] isPackageExtension: @"kext"], @""); STAssertTrue([[NSWorkspace sharedWorkspace] isPackageExtension: @"clr"], @""); /* The following tests depend on having applications installed that are not included in Mac OS X: .esproj Espresso, tested with version 2.0.5 ( http://macrabbit.com/espresso/ ) .dtps Instruments, included in Xcode, tested with version 4.5 (4523) */ STAssertTrue([[NSWorkspace sharedWorkspace] isPackageExtension: @"esproj"], @""); STAssertTrue([[NSWorkspace sharedWorkspace] isPackageExtension: @"dtps"], @""); } </code></pre> <p><strong>Edit</strong>: The test above has been edited to include additional example extensions (original post only used "rtf" and "rtfd").</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload