Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html/" rel="nofollow noreferrer">OS X packages (and bundles)</a> are usually defined by their extension. Simply create a directory with an <code>.app</code> extension to see it be presented as a (broken) application in the Finder.</p> <p>The <a href="http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles.html" rel="nofollow noreferrer">official documentation</a> lists the following ways to define bundles:</p> <blockquote> <p>The Finder considers a directory to be a package if any of the following conditions are true:</p> <ul> <li>The directory has a known filename extension: .app, .bundle, .framework, .plugin, .kext, and so on.</li> <li>The directory has an extension that some other application claims represents a package type; see “Document Packages.”</li> <li>The directory has its package bit set.</li> </ul> <p>The preferred way to specify a package is to give the package directory a known filename extension. For the most part, Xcode takes care of this for you by providing templates that apply the correct extension. All you have to do is create an Xcode project of the appropriate type.</p> </blockquote> <p>The simplest way to detect packages then is to detect those extensions. The quick and dirty way is to simply look for a hard-coded list of extensions, using the above documentation as your guide.</p> <p>The next step up is to query the OS if a given extension has been registered as a Document Package. See <a href="https://stackoverflow.com/questions/16933733/how-to-check-whether-directories-with-a-given-extension-are-shown-by-the-finder">How to check whether directories with a given extension are shown by the Finder as a package?</a></p> <p>To detect the package bit on directories, you'll have to use the <a href="https://pypi.python.org/pypi/xattr" rel="nofollow noreferrer"><code>xattr</code> library</a> to retrieve the <code>u'com.apple.FinderInfo'</code> key and then use the <a href="http://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-8A428/Finder.h" rel="nofollow noreferrer"><code>Finder.h</code> header info</a> to decode the binary data returned; the <code>kHasBundle</code> flag is 0x2000:</p> <pre><code>attrs = xattr.getxattr('/path/to/dir', u'com.apple.FinderInfo') ispackage = bool(ord(attrs[8]) &amp; 0x20) # I *think* this is correct; works for hidden dirs and &amp; 0x40 </code></pre>
 

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