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.

  1. Open terminal 
  2. Use pkgutilto extract the content in the .pkg
  3. Change directory to Out
  4. Make a new directory called payload_content
  5. Change directory to payload_content
  6. Use pax to Extract Payload content
pkgutil --expand /Volumes/Stuff/mypackage.pkg /Volumes/Stuff/Out

cd /Volumes/Stuff/Out

mkdir payload_content

cd payload_content

pax -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

  1. Open terminal 
  2. Make sure you are in directory that we created earlier payload_content
  3. Use find to see if macOS have created some DS_Store files and delete them
  4. Use find and cpio (classic Unix archive tool) and gzip (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 as Payload, ready to be inserted into a .pkg
  5. Change directory to Out
  6. Use rm to delete Payload_Content folder
  7. Use pkgutil to repackage pkg with a new name
cd /Volumes/Stuff/Out/payload_content

find . -name '.DS_Store' -type f -delete

find . | cpio -o --format odc | gzip -c > ../Payload

cd /Volumes/Stuff/Out

rm -rf Payload_Content


pkgutil --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).

  1. Open terminal 
  2. Use codesign to sign your .pkg
sudo codesign --sign "Developer ID Installer: Your Name" /Volumes/Stuff/mypackage2.pkg

Comments