Viewing entries tagged

Creating OS X Package Files (.pkg) In Terminal


Creating OS X Package Files (.pkg) In Terminal

2018 Update

Everything below still works, but for the past few years I have been using munkipkg for the generation of all my packages. Although Munki is in the name, it is just a nice command-line tool by Greg Neagle for creating packages.

OS X includes a handy Terminal tool called ‘pkgbuild’ for compiling package installer files.

To demonstrate pkgbuild I will use my 'Enable ARD' (Apple Remote Desktop) package.

This package places an script into /Library/Scripts/Enable ARD/ and creates a LaunchDaemon to run that script on boot. The script simply removes all users from Remote Management (ARD) and then gives full access to a specified username, ensuring that user has remote access.


To keep things organised when creating a package, I create a directory consisting of the following files and folders: Includes the package name, versioning information and is used to compile the package.

complied: Is where the product of is written.

files: Contains the files the package will copy into place.

scripts: Can contain preinstall and/or postinstall scripts. A preinstall script is run before the contents of files is copied into place, whereas postinstall is after. It is important not to give these script files an extension.

Contents of


# Name of the package.

# Once installed the identifier is used as the filename for a receipt files in /var/db/receipts/.

# Package version number.

# The location to copy the contents of files.
INSTALL_LOCATION="/Library/Scripts/Enable ARD"

# Remove any unwanted .DS_Store files.
find files/ -name '*.DS_Store' -type f -delete

# Set full read, write, execute permissions for owner and just read and execute permissions for group and other.
/bin/chmod -R 755 files

# Remove any extended attributes (ACEs).
/usr/bin/xattr -rc files

# Build package.
/usr/bin/pkgbuild \
    --root files/ \
    --install-location "$INSTALL_LOCATION" \
    --scripts scripts/ \
    --identifier "$IDENTIFIER" \
    --version "$VERSION" \


Contents of scripts/postinstall:


# Filename of script.

# Path to script.
PATH="/Library/Scripts/Enable ARD"

# Script identifier (same as package identifier).


# Write LaunchDaemon plist file.
echo '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
</plist>' > "$LAUNCH_DAEMON_PLIST"

# Load the new LaunchDaemon.
/bin/launchctl load "$LAUNCH_DAEMON_PLIST"

# Check LaunchDaemon is loaded.
STATUS=`/bin/launchctl list | /usr/bin/grep $IDENTIFIER | /usr/bin/awk '{print $3}'`

if [ "$STATUS" = "$IDENTIFIER" ]
        echo "Success: LaunchDaemon loaded."
        exit 0      
        echo "Error: LaunchDaemon not loaded."      
        exit 1


Contents of files/


# Username of account used for ARD access.

# Revoke ARD access for all users.
/System/Library/CoreServices/RemoteManagement/ -activate -configure -access -off

# Assign full privileges to an ARD Administrator account.
/System/Library/CoreServices/RemoteManagement/ -activate -configure -access -on -users $USER -privs -all -restart -agent -menu

# Set Remote Management to only accept the user specified.
/System/Library/CoreServices/RemoteManagement/ -configure -allowAccessFor -specifiedUsers

Ready To Compile

To compile a package:

Open Terminal,

type 'cd ' (change directory),

drag the folder containing into Terminal and hit return,

type 'chmod +x' to make it executable,

lastly type ‘./’ and hit return.

You should now have a new package file in the compiled directory.

Bonus Tips

Use Full Paths

When writing scripts it is important to include the full path to any binaries used. You can easily find the full path of a binary with the ‘which’ command.

Check Your Packages

Sometimes I want to know what a package would do without running it. This is where the Finder QuickLook plug-in called ‘Suspicious Package’ comes in handy, as it shows where files would be copied and the contents of any preinstall and postinstall scripts. I also like to use Suspicious Package on my own package files to ensure files are being copied into the correct directory and any scripts are present.

Read The Manual

My example script does not take advantage of pkgbuild’s complete feature-set, for example packages can also be signed to prove authenticity. If you want to know more about pkgbuild simply read the man (manual) file, by typing ‘man pkgbuild’ into Terminal.


A Guide to Installing & Uninstalling Mac Applications


A Guide to Installing & Uninstalling Mac Applications

People making the switch to Mac often ask, “How do I install programs and what’s the equivalent to ‘Add/Remove Programs’ on a Mac?” To answer this question I have put together a guide that covers the three main methods of installing and uninstalling applications in Apple’s Mac OS X:


Mac App Store: Apple introduced the MAS back in Mac OS X 10.6.6 (Snow Leopard) and it is now the preferred method for installing Apple approved applications. The Mac App Store notifies users when an app update is available and a new feature in OS X 10.9 (Mavericks) can even automatically install updates for you. Applications purchased through the MAS are linked to your Apple ID, allowing you to install purchased apps on multiple Macs for no additional charge. Another benefit is that you don’t need to keep track of any serial numbers.

Install: Simply click the price tag button and then click ‘Buy App’ to confirm the purchase. The app icon then literately jumps out of the MAS and into your Lauchpad.

Uninstall: Open Launchpad, click and hold your cursor on an app icon until you see the app icons shaking (I imagine that they are scared that you are going to delete them), then click the little cross in the top left corner of the app icon and confirm by clicking ‘Delete.’

Examples: iBooks Author, Flutter, Muse


Drag & Drop: These generally download as a .dmg (disk image) file, however I have also come across .zip and tar.gz (compressed archive) files, which all just contain a .app file. Apps are often distributed this way if they do not meet MAS requirements. You will find many community driven applications (open source) distributed this way as their licensing conflicts with Apple’s MAS Terms of Service.

Install: Double click to mount the .dmg file and drag the app icon into your Applications directory to install. Often .dmg files will include an alias to your Applications directory, so you don’t need to fiddle with opening another Finder window.


Uninstall: The easiest way to remove these apps is with FreeMacSoft’s AppCleanerOtherwise you can manually remove the app by going to Applications in Finder and dragging the app into the Trash.

Examples: Google Chrome, Mozilla Firefox, VLC


Installer Package: These are generally used if an application needs to install files outside of the Applications directory and/or needs to run an install script. An install of a .pkg or .mpkg file looks very similar to setup wizards found on the Windows operating systems.

Tip: If you ever want to extract something out of a .pkg file, you can use the free app ‘unpkg.’ It’s great for extracting the .app file in situations where an installer will refuse to run on your bleeding edge operating system.

Install: Double click the installer package file and click through the wizard.


Tip: I recommend installing a free Finder QuickLook plug-in called ‘Suspicious Package,’ it presents detailed information about what an installer package is configured to do. Download Suspicious Package here, mount the .dmg and then click ‘Go’ → ‘Go to Folder’ then type ~/Library/.


Create a new folder called ‘QuickLook’ and drag ‘Suspicious Package.qlgenerator’ into it.


You will need to log out or restart your computer for Finder to detect the plug-in. Once installed, simply select a .pkg file and hit space to see detailed information about that package.



Uninstall: By far the easiest way is to use AppCleaner. The next best thing is using a tool such as Suspicious Package to find where the package places files and manually go around and delete them. If you are feeling really geeky you could avoid using Suspicious Package and use the Terminal command ‘lsbom -lfs `pkgutil --bom /PATH/TO/PACKAGE/FILE.pkg`’ to get an idea of where the package places files.

Examples: Adobe Flash Player, Oracle Java, Microsoft Office


Unless you have used AppCleaner you’ll find settings/configuration files created by that application are left behind. If you want an application to behave like it’s never been opened before, you will need to trash any preference files containing to the application or developer's name. Open Finder and click ‘Go’ → ‘Go to Folder’ then type the following paths:

User specific settings: ~/Application Support/ and ~/Preferences/

System wide settings: /Library/Application Support/ and /Library/Preferences/