Expand flatten content from pkg

When working with a macOS .pkg installer, you might occasionally need to peek inside and tweak a specific file — maybe to adjust a config, replace a resource, or fix a detail before installation. In this article, we’ll walk through how to safely unpack a .pkg, locate and edit the file you need, and repackage it cleanly for installation. A simple, practical guide to customizing macOS packages without breaking the signing or install process.
Summary in this article:
- Expand a
.pkg - Unpack its payload
- Modify files
- Rebuild
- Re-sign installer
Expand the content in the package.
- Open terminal
- Use
pkgutilto extract the content in the .pkg - Change directory to
Out - Make a new directory called
payload_content - Change directory to
payload_content - Use
paxto Extract Payload content
pkgutil --expand /Volumes/Stuff/mypackage.pkg /Volumes/Stuff/Outcd /Volumes/Stuff/Outmkdir payload_contentcd payload_contentpax -rz -f ../Payload
Now adjust the files that needs adjustment in the package.
Example if you have a pkg that adds a plist file to /Library/LaunchAgents or /Library/LaunchDaemons that has the key to run at load as true.
<key>RunAtLoad</key>
<true/>
Change to
<key>RunAtLoad</key>
<false/>
Now when you want to distibute this pkg to several users the app will NOT start automaticlly.
Rebuild pkg
- Open terminal
- Make sure you are in directory that we created earlier
payload_content - Use
findto see if macOS have created someDS_Storefiles and delete them - Use
findandcpio(classic Unix archive tool) andgzip(compresses) into a new Payload. (Collects all files in the current folder. Packages them into a cpio archive (odc format). Compresses it with gzip. Saves it asPayload, ready to be inserted into a.pkg - Change directory to Out
- Use
rmto delete Payload_Content folder - Use
pkgutilto repackage pkg with a new name
cd /Volumes/Stuff/Out/payload_contentfind . -name '.DS_Store' -type f -deletefind . | cpio -o --format odc | gzip -c > ../Payloadcd /Volumes/Stuff/Out
rm -rf Payload_Contentpkgutil --flatten /Volumes/Stuff/Out /Volumes/Stuff/mypackage2.pkg
Re-signing pkg
macOS may block modified installers. So we need to sign it again.
Sign it with your developer certificate (replace with your identity).
- Open terminal
- Use
codesignto sign your .pkg
sudo codesign --sign "Developer ID Installer: Your Name" /Volumes/Stuff/mypackage2.pkg
Comments