osx - Identify directories that are packages in Mac OS X with Python -


the mac os x finder uses concept of "packages" make contents of folders opaque user. i'm using os.walk() enumerate directory tree , want skip enumeration on packages such application bundles.

the mdls commandline utility can used check whether com.apple.package in kmditemcontenttypetree attribute. only/best way detect whether folder package drop os.system , use mdls after detecting os indeed darwin?

as aside, solution seems depend on spotlight metadata understand populated from files/directories themselves. makes me wonder whether there method check whether directory package outside of mdls. perhaps i'm missing something.

os x packages (and bundles) defined extension. create directory .app extension see presented (broken) application in finder.

the official documentation lists following ways define bundles:

the finder considers directory package if of following conditions true:

  • the directory has known filename extension: .app, .bundle, .framework, .plugin, .kext, , on.
  • the directory has extension other application claims represents package type; see “document packages.”
  • the directory has package bit set.

the preferred way specify package give package directory known filename extension. part, xcode takes care of providing templates apply correct extension. have create xcode project of appropriate type.

the simplest way detect packages detect extensions. quick , dirty way hard-coded list of extensions, using above documentation guide.

the next step query os if given extension has been registered document package. see how check whether directories given extension shown finder package?

to detect package bit on directories, you'll have use xattr library retrieve u'com.apple.finderinfo' key , use finder.h header info decode binary data returned; khasbundle flag 0x2000:

attrs = xattr.getxattr('/path/to/dir', u'com.apple.finderinfo') ispackage = bool(ord(attrs[8]) & 0x20)  # *think* correct; works hidden dirs , & 0x40 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -