Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created August 18, 2016 17:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pudquick/d64234a093e223e319d2d7a104d4b85e to your computer and use it in GitHub Desktop.
Save pudquick/d64234a093e223e319d2d7a104d4b85e to your computer and use it in GitHub Desktop.
Programmatically access package receipt information using the OS X PrivateFramework PackageKit (same one pkgutil uses) with python and pyobjc
import objc
packagekit_bundle = objc.loadBundle('PackageKit', module_globals=globals(), bundle_path='/System/Library/PrivateFrameworks/PackageKit.framework', scan_classes=False)
PKReceipt = objc.lookUpClass('PKReceipt')
receipts = PKReceipt.receiptsOnVolumeAtPath_('/')
first_receipt = receipts[0]
# Things you can look up:
# installPrefixPath
# installProcessName
# installDate
# packageVersion
# packageIdentifier
# description
# receiptStoragePaths
# packageGroups
# >>> first_receipt.packageVersion()
# u'10.11.4.1.1.1457768702'
# Direct access to the BOM for the package receipt
# >>> bom = first_receipt._BOM()
# >>> e = bom.directoryEnumerator()
# >>> e.nextObject()
# u'System'
# >>> e.nextObject()
# u'System/Library'
# >>> e.nextObject()
# u'System/Library/CoreServices'
# >>> e.nextObject()
# u'System/Library/CoreServices/SystemVersion.plist'
# [...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment