Skip to content

Instantly share code, notes, and snippets.

@jlehikoinen
Last active April 8, 2020 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlehikoinen/ce8858e328636c39a958bcf8b1a83395 to your computer and use it in GitHub Desktop.
Save jlehikoinen/ce8858e328636c39a958bcf8b1a83395 to your computer and use it in GitHub Desktop.
Codesign macOS Installer package
# Automator > Quick Action
# Workflow receives current "files or folders" in "Finder"
# Add "Run Shell Script" action
# Copy script below to "Run Shell Script" window
# Replace <codesigning certificate> at row 28 with your certificate information
# Save quick action as: "Sign Installer package"
# Quick Actions live in: ~/Library/Services
# Receives files and folders
while read -r file; do
dest_dir="${file%/*}"
filename="${file##*/}"
filename="${filename%.*}"
ext="${file##*.}"
if [[ $ext != "pkg" ]]; then
/usr/bin/osascript -e "display alert \"Error: Only .pkg files supported\""
exit 1
fi
if [[ -f "$dest_dir"/"${filename}_signed.pkg" ]]; then
/usr/bin/osascript -e "display alert \"Error: Target file already exists\""
exit 1
fi
# Sign pkg using certificate found in keychain
/usr/bin/productsign --sign "Developer ID Installer: <codesigning certificate>" "$file" "$dest_dir"/"${filename}_signed.pkg"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment