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
@rogierlommers

Copy link
Copy Markdown

Thanks! One question though, I use the bash script below as a test, but where can I find the output of the script?

#!/bin/bash
echo "$(date) - start backup" > /Users/me/Dropbox/backup.log
ls
sleep 10
echo "$(date) - start backup" >> /Users/me/Dropbox/backup.log

@rogierlommers

Copy link
Copy Markdown

Or do I need to open a terminal window in the shell script?

ghost commented Sep 1, 2017

Copy link
Copy Markdown

@oubiwann, considered making this brewable? I like your version the best, because it includes the additional options like icon (which I was going to add as well prior to finding your fork).

brew install appify

https://apple.stackexchange.com/questions/97065/how-do-i-write-a-homebrew-recipe

I've never done it before, but it appears to be simple enough.

@pablonosh

pablonosh commented Jul 24, 2018

Copy link
Copy Markdown

I get

"The application cannot be opened because it has an incorrect executable format." on High Sierra.

You can’t open the application “iPhone Bitrise Build” because it is not supported on this type of Mac.

@mdfalcon104

Copy link
Copy Markdown

The icon does not update if I replace by new one?

@imanassypov

Copy link
Copy Markdown

What needs to be done for the new app to be disoverable by system_profiler, as in 'system_profiler SPApplicationsDataType' ?
Is there a way to 'register' the newly packaged app so it shows as 'installed'?

@oubiwann

Copy link
Copy Markdown
Author

Yikes, I had no idea people were leaving comments here until today -- sorry, all!

I haven't used the script since 2016; I can give it a shot, and see if it still works.

@dlpigpen: usually running touch Your.app refreshes icons in Mac OS X ...

@b3z

b3z commented May 6, 2021

Copy link
Copy Markdown

All Bundles I create on bigSure are not compatible it says.

@yogasw

yogasw commented May 20, 2021

Copy link
Copy Markdown

@varenc

varenc commented Dec 28, 2021

Copy link
Copy Markdown

This worked great for turning a script into a .app! But if you're doing this to deal with permission stuff, I'll note that the .app still isn't treated like one by macOS for security permission purposes. For example, if your script needs the Accessibility permission, macOS asks you to grant Accessibility permissions to bash (or zsh/sh/env/whatever), even though it's run from this .app. The heavier-weight Platypus app, linked above, addresses this for me so that the .app itself is what needs the permissions. Though I imagine for many this isn't important.

@denwald

denwald commented Jul 28, 2022

Copy link
Copy Markdown

Thank you for this convenient script. It works like a charm on my Intel iMac running Monterey. On my MacBook Air M1 (Apple Silicon) on the other hand I only get a pop up which offers to install Rosetta emulation. This does not make a lot of sense to me, since I've only packaged a bash script. Any idea if this is a general limitation of macOS and the M1 SOC?

@bikeridercz

bikeridercz commented May 13, 2024

Copy link
Copy Markdown

Hi ! Something has to change over the time. The script successfully creates an .APP but it does not work in these days. I tried to make simple shell script that works when if invoked directly, however it does not work if wrapped by .APP. Any idea ?

radim@Radim-MacBookPro14 % ./test         
Ahoj !

radim@Radim-MacBookPro14 % ./test.app/Contents/MacOS/test 
Ahoj !

radim@Radim-MacBookPro14 % ./test.app 
zsh: permission denied: ./test.app

radim@Radim-MacBookPro14 % open ./test.app
The application cannot be opened for an unexpected reason, error=Error Domain=NSOSStatusErrorDomain Code=-10661 "(null)" UserInfo={_LSLine=4129, _LSFunction=_LSOpenStuffCallLocal}

radim@Radim-MacBookPro14 % sw_vers
ProductName:		macOS
ProductVersion:		14.4.1
BuildVersion:		23E224

@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