Skip to content

Instantly share code, notes, and snippets.

@oubiwann
Forked from advorak/appify.sh
Last active August 6, 2026 06:58
Show Gist options
  • Select an option

  • Save oubiwann/453744744da1141ccc542ff75b47e0cf to your computer and use it in GitHub Desktop.

Select an option

Save oubiwann/453744744da1141ccc542ff75b47e0cf to your computer and use it in GitHub Desktop.
appify — create the simplest possible Mac app from a shell script (adds an application icon)
#!/usr/bin/env bash
#
# appify — create the simplest possible Mac app from a shell script
#
# v5.0.0
#
# Copyright (c) Thomas Aylott <http://subtlegradient.com/>
# Modified by Mathias Bynens <http://mathiasbynens.be/>
# Modified by Andrew Dvorak <http://OhReally.net/>
# Rewritten by Duncan McGreggor <http://github.com/oubiwann/>
# Updated 2026 — see changelog below
#
# Original: https://gist.github.com/mathiasbynens/674099
# This fork: https://gist.github.com/oubiwann/453744744da1141ccc542ff75b47e0cf
#
# Changelog (v5.0.0):
# - Fix Apple Silicon: add LSArchitecturePriority + LSRequiresNativeExecution
# to Info.plist so macOS doesn't misidentify shell-script bundles as Intel
# apps or prompt for Rosetta (fixes -10661 / "incorrect executable format"
# errors on M1/M2/M3+)
# - Add CFBundleIdentifier to Info.plist (required by modern macOS; auto-
# generated from app name if not supplied via --identifier)
# - Validate that the source script has a shebang line (missing shebang is
# the #1 cause of "PowerPC application" errors)
# - Register finished bundle with LaunchServices so it appears in Spotlight,
# system_profiler, and open(1) immediately
# - Flush icon cache via `touch` after build
# - New flags: --identifier, --version-string, --hidden, --overwrite
# - Properly quote all path variables (fixes names with spaces)
# - Replace backtick command substitution with $()
# - Fall back gracefully when default icon path doesn't exist
# - Use modern DTD URL in plist (Apple//DTD, not Apple Computer//DTD)
# - Exit codes: 0 = success, 1 = usage/help, 2 = error
set -euo pipefail
VERSION=5.0.0
SCRIPT=$(basename "$0")
# Defaults
APPNAME="My App"
APPICONS="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns"
APPSCRIPT=""
APPID=""
APPVERSION=""
HIDDEN=false
OVERWRITE=false
# ── Helpers ──────────────────────────────────────────────────────────────────
usage() {
cat <<EOF
$SCRIPT v${VERSION} for macOS
https://gist.github.com/oubiwann/453744744da1141ccc542ff75b47e0cf
Usage:
$SCRIPT [options]
Options:
-h, --help Print this help message, then exit
-s, --script FILE Shell script to appify (required)
-n, --name NAME Application name (default "$APPNAME")
-i, --icons FILE .icns file to use as the app icon
(default: macOS generic app icon)
-I, --identifier ID CFBundleIdentifier, e.g. com.example.myapp
(default: auto-generated from app name)
-V, --version-string Version string for the app bundle (e.g. "1.0.0")
-H, --hidden Set LSUIElement=1 so the app runs without a Dock
icon or menu bar (useful for background tasks)
-f, --overwrite Overwrite an existing .app bundle
-v, --version Print the version of this script, then exit
Description:
Creates the simplest possible Mac app from a shell script.
Appify has one required parameter — the script to appify:
$SCRIPT --script my-app-script.sh
Give your app a custom name with '--name':
$SCRIPT --script my-app-script.sh --name "Sweet"
Supply a custom icon (must be .icns format):
$SCRIPT -s my-app.sh -n "Sweet" -i my-icon.icns
Set a reverse-DNS identifier (recommended):
$SCRIPT -s my-app.sh -n "Sweet" -I com.example.sweet
Notes:
• Your script MUST have a shebang line (e.g. #!/bin/bash or
#!/usr/bin/env bash) as its very first line, or macOS will
refuse to run the app.
• On Apple Silicon Macs the generated Info.plist includes
LSArchitecturePriority and LSRequiresNativeExecution so that
macOS does not misidentify the bundle as an Intel app.
• If macOS has cached a stale architecture flag for a previous
build with the same bundle identifier, change the identifier
(--identifier) or run:
/System/Library/Frameworks/CoreServices.framework/\\
Frameworks/LaunchServices.framework/Support/lsregister \\
-f YourApp.app
Copyright:
Copyright (c) Thomas Aylott <http://subtlegradient.com/>
Modified by Mathias Bynens <http://mathiasbynens.be/>
Modified by Andrew Dvorak <http://OhReally.net/>
Rewritten by Duncan McGreggor <http://github.com/oubiwann/>
EOF
exit 1
}
version() {
echo "v${VERSION}"
exit 0
}
error() {
echo >&2
echo "ERROR: $1" >&2
echo >&2
usage
}
warn() {
echo "WARNING: $1" >&2
}
# Sanitise a name into a plausible reverse-DNS identifier.
# "My Cool App" → "local.my-cool-app"
make_bundle_id() {
local name="$1"
local slug
slug=$(echo "$name" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd 'a-z0-9-.')
echo "local.appify.${slug}"
}
# ── Argument parsing ─────────────────────────────────────────────────────────
while :; do
case "${1:-}" in
-h | --help ) usage ;;
-s | --script ) APPSCRIPT="${2:-}"; shift ;;
-n | --name ) APPNAME="${2:-}"; shift ;;
-i | --icons ) APPICONS="${2:-}"; shift ;;
-I | --identifier ) APPID="${2:-}"; shift ;;
-V | --version-string ) APPVERSION="${2:-}"; shift ;;
-H | --hidden ) HIDDEN=true ;;
-f | --overwrite ) OVERWRITE=true ;;
-v | --version ) version ;;
-- ) shift; break ;;
-* ) error "unknown option '$1'" ;;
* ) break ;;
esac
shift
done
# ── Validation ───────────────────────────────────────────────────────────────
if [[ -z "${APPSCRIPT}" ]]; then
error "the script to appify must be provided (--script FILE)"
fi
if [[ ! -f "${APPSCRIPT}" ]]; then
error "can't find the script '${APPSCRIPT}'"
fi
if [[ ! -x "${APPSCRIPT}" ]]; then
warn "'${APPSCRIPT}' is not executable — adding +x"
chmod +x "${APPSCRIPT}"
fi
# Check for a shebang — its absence is the single most common cause of
# "PowerPC application" / "incorrect executable format" errors.
FIRSTLINE=$(head -n1 "${APPSCRIPT}")
if [[ "${FIRSTLINE}" != "#!"* ]]; then
cat >&2 <<'SHEBANG_WARNING'
WARNING: Your script does not start with a shebang line (e.g. #!/bin/bash).
macOS will almost certainly refuse to launch the resulting .app.
Add one of the following as the VERY FIRST line of your script:
#!/bin/bash
#!/usr/bin/env bash
#!/bin/zsh
#!/usr/bin/env zsh
SHEBANG_WARNING
fi
APPBUNDLE="${APPNAME}.app"
if [[ -e "${APPBUNDLE}" ]]; then
if [[ "${OVERWRITE}" == true ]]; then
echo "Removing existing '${APPBUNDLE}' ..."
rm -rf "${APPBUNDLE}"
else
error "the bundle '$(pwd)/${APPBUNDLE}' already exists (use --overwrite to replace)"
fi
fi
# Icons — fall back if the default path has moved on this macOS version.
if [[ ! -f "${APPICONS}" ]]; then
if [[ "${APPICONS}" == /System/* ]]; then
warn "default icon not found at '${APPICONS}'; the app will use a blank icon"
APPICONS=""
else
error "can't find the icons file '${APPICONS}'"
fi
fi
# Auto-generate a bundle identifier if none was supplied.
if [[ -z "${APPID}" ]]; then
APPID=$(make_bundle_id "${APPNAME}")
fi
# ── Build ────────────────────────────────────────────────────────────────────
APPDIR="${APPBUNDLE}/Contents"
mkdir -vp "${APPDIR}"/{MacOS,Resources}
# Copy the script as the executable.
cp -v "${APPSCRIPT}" "${APPDIR}/MacOS/${APPNAME}"
chmod +x "${APPDIR}/MacOS/${APPNAME}"
# Copy the icon (if available).
if [[ -n "${APPICONS}" ]]; then
cp -v "${APPICONS}" "${APPDIR}/Resources/${APPNAME}.icns"
fi
# ── Info.plist ───────────────────────────────────────────────────────────────
#
# Key additions vs earlier versions:
# • CFBundleIdentifier — required by modern LaunchServices; without it the
# bundle is unregistrable and `open` may fail with -10661.
# • LSArchitecturePriority — tells macOS this bundle should run natively on
# arm64, preventing the Rosetta prompt on Apple Silicon.
# • LSRequiresNativeExecution — reinforces the above.
# • CFBundleSignature uses "4242" (arbitrary but valid 4-char creator code);
# "????" caused problems on some older macOS versions.
PLIST="${APPDIR}/Info.plist"
cat <<PLIST_EOF > "${PLIST}"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>${APPNAME}</string>
<key>CFBundleGetInfoString</key>
<string>${APPNAME}</string>
<key>CFBundleIdentifier</key>
<string>${APPID}</string>
<key>CFBundleName</key>
<string>${APPNAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>4242</string>
PLIST_EOF
# Icon reference (omit if no icon was copied).
if [[ -n "${APPICONS}" ]]; then
cat <<ICON_EOF >> "${PLIST}"
<key>CFBundleIconFile</key>
<string>${APPNAME}</string>
ICON_EOF
fi
# Version string.
if [[ -n "${APPVERSION}" ]]; then
cat <<VER_EOF >> "${PLIST}"
<key>CFBundleShortVersionString</key>
<string>${APPVERSION}</string>
<key>CFBundleVersion</key>
<string>${APPVERSION}</string>
VER_EOF
fi
# LSUIElement — hides the app from the Dock and ⌘-Tab switcher.
if [[ "${HIDDEN}" == true ]]; then
cat <<HIDE_EOF >> "${PLIST}"
<key>LSUIElement</key>
<true/>
HIDE_EOF
fi
# Architecture hints for Apple Silicon.
cat <<ARCH_EOF >> "${PLIST}"
<key>LSArchitecturePriority</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>LSRequiresNativeExecution</key>
<true/>
</dict>
</plist>
ARCH_EOF
# ── Post-build ───────────────────────────────────────────────────────────────
# Touch the bundle so Finder refreshes its icon cache.
touch "${APPBUNDLE}"
# Register with LaunchServices so the app is discoverable by Spotlight,
# `open -a`, system_profiler, etc. The lsregister binary has lived at this
# path since at least 10.5; if it's missing we just skip it.
LSREGISTER="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister"
if [[ -x "${LSREGISTER}" ]]; then
"${LSREGISTER}" -f "${APPBUNDLE}" 2>/dev/null && \
echo "Registered '${APPBUNDLE}' with LaunchServices" || \
warn "lsregister failed — the app will still work but may not appear in Spotlight until you move it to /Applications"
fi
echo
echo "Created '$(pwd)/${APPBUNDLE}'"
echo " Bundle ID : ${APPID}"
if [[ -n "${APPVERSION}" ]]; then
echo " Version : ${APPVERSION}"
fi
if [[ "${HIDDEN}" == true ]]; then
echo " LSUIElement: yes (hidden from Dock)"
fi
echo
echo "To launch: open '${APPBUNDLE}'"
echo
@oubiwann

Copy link
Copy Markdown
Author

Since folks are still using this, I've updated the script again (including some hints for most common sources of problems and some new capabilities for addressing issues folks have run into on their machines).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment