Skip to content

Instantly share code, notes, and snippets.

@SoCuul
Last active April 10, 2026 01:13
Show Gist options
  • Select an option

  • Save SoCuul/fac31045e23f8397487a4bfd43de46b0 to your computer and use it in GitHub Desktop.

Select an option

Save SoCuul/fac31045e23f8397487a4bfd43de46b0 to your computer and use it in GitHub Desktop.
Notarize & staple bundles/DMGs with Apple
#!/usr/bin/env bash
set -uo pipefail
PROFILE="<keychain-profile-name>"
# Check for missing arguments
if [ "$#" -lt 1 ]
then
echo
echo "Usage: notarize <bundle/dmg>"
echo
exit 1
fi
bundle="$1"
# https://stackoverflow.com/a/78304619/14239936
function submit() {
xcrun notarytool submit --no-progress -f json \
--keychain-profile "$PROFILE" \
"$bundle.zip" | \
jq -r .id
}
function status() {
xcrun notarytool log \
--keychain-profile "$PROFILE" \
"$submissionId" > /dev/null 2>&1
}
function log() {
echo
xcrun notarytool log \
--keychain-profile "$PROFILE" \
"$submissionId"
}
if [ -f "$bundle.zip" ]; then
rm -i "$bundle.zip"
fi
echo
# Compress
echo -n "Compressing..."
/usr/bin/ditto -c -k --keepParent "$bundle" "$bundle.zip"
echo " Done"
# Upload
echo -n "Uploading..."
submissionId="$(submit)"
echo " Done"
if [[ -z "$submissionId" ]]; then
exit 1
fi
# Notarize
echo
echo "Submission ID: $submissionId"
echo
echo -n "Notarizing..."
until status "$submissionId"
do
sleep 2 || true
done
echo " Done"
log "$submissionId"
# Staple
echo
xcrun stapler staple "$bundle"
#!/usr/bin/env bash
set -euo pipefail
# Check for missing arguments
if [ "$#" -lt 1 ]
then
echo
echo "Usage: notarizeverify <bundle/dmg>"
echo
exit 1
fi
xcrun stapler validate "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment