> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.appaloosa.io/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to deploy macOS apps with Appaloosa

Appaloosa automatically installs your apps on your enrolled Mac computers. The expected format is a signed .pkg. Depending on what the app vendor provides, you're in one of the three cases below.

| Your case | What you need to do |
| --- | --- |
| The vendor provides a .pkg | Nothing: add the file to Appaloosa as is |
| The vendor provides a .app (often inside a .dmg or .zip) | Build a signed .pkg from the .app |
| You want to run a script | Put the script in a signed .pkg |

# The app is already a .pkg

These apps can be distributed as they are. Add the file to Appaloosa, fill in the app's information, then deploy it.

Don't re-sign a .pkg provided by a vendor: your signature would replace theirs.

# The app is a .app

You need to build your own .pkg and sign it with a **Developer ID Installer** certificate from your Apple Developer account.

## Before you start

* A Mac with Apple's command line tools (`xcode-select --install`).
* A Developer ID Installer certificate installed in your keychain. Follow [Apple's guide](https://developer.apple.com/help/account/certificates/create-developer-id-certificates/) to create it. It requires an Apple Developer Program membership, and only the Account Holder can create it.

Watch the certificate type: a Developer ID **Application** certificate signs apps, not .pkg files. You need the Developer ID **Installer** certificate.

## 1. Get the name of your certificate

```
security find-identity -v | grep "Developer ID Installer"
```

The command prints the full name to use, for example `Developer ID Installer: Your Company (ABCDE12345)`.

## 2. Prepare the .app file

If the app ships in a .dmg, open it and copy the .app to a working folder. If it ships in a .zip, unzip it.

An app downloaded from a browser carries a quarantine flag. Remove it before building the .pkg, otherwise it's embedded in the package:

```
xattr -dr com.apple.quarantine ~/Downloads/TextMate.app
```

Don't change anything else in the .app: its original signature must stay intact.

## 3. Build the signed .pkg

```
productbuild --component ~/Downloads/TextMate.app /Applications \  --sign "Developer ID Installer: Your Company (ABCDE12345)" \  ~/Downloads/TextMate.pkg
```

* `/Applications`, after the path to the .app, is the install folder on your users' Mac computers. With it, you don't need to move the app into your own /Applications folder first.
* `--sign` takes the exact name from step 1. macOS may ask you to allow keychain access the first time you sign.

## 4. Check the .pkg

```
pkgutil --check-signature ~/Downloads/TextMate.pkg
```

The output should read `signed by a developer certificate issued by Apple for distribution`, followed by the name of your certificate. You can then add the .pkg to Appaloosa.

## Troubleshooting

| Message | Likely cause |
| --- | --- |
| Could not find appropriate signing identity | The name passed to --sign doesn't match a Developer ID Installer certificate in your keychain. Run the step 1 command again and copy the full name. |
| The step 1 command prints nothing | The certificate or its private key isn't in this Mac's keychain. Install it from the Mac used to create it, or create a new one. |
| pkgutil reports no signature | The .pkg was built without the --sign option. Run step 3 again. |

# Run a script with a .pkg

You can run a script on your Mac computers by putting it in a signed .pkg, for example to install a tool or apply a setting.

1. Create a `scripts` folder containing your script, named exactly `postinstall`, with no extension. It must start with `#!/bin/bash` (or `#!/bin/zsh`) and be executable:

```
chmod +x scripts/postinstall
```
2. Build the package, then sign it:

```
pkgbuild --nopayload --scripts scripts \  --identifier com.yourcompany.myscript --version 1.0 \  myscript-component.pkgproductbuild --package myscript-component.pkg \  --sign "Developer ID Installer: Your Company (ABCDE12345)" \  myscript.pkg
```
3. Check `myscript.pkg` with `pkgutil --check-signature`, then add it to Appaloosa.

The script runs with administrator (root) privileges, with no user session. Test it on a test Mac first, and end it with `exit 0`: any other exit code makes the installation fail.