Last active
September 4, 2021 16:23
-
-
Save pixelomer/09f841838fc5af9c935f18aaca36c253 to your computer and use it in GitHub Desktop.
Simple script to create macOS application bundles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [[ $1 == "--help" ]] || [[ $1 == "-h" ]]; then | |
echo "Usage: appgen [--help]" | |
echo "" | |
echo "AppGen is a tool for creating macOS Application bundles from the terminal. This is an interactive script and doesn't require any arguments to be passed." | |
echo "" | |
echo "+ Application Name: Name of the application. Cannot contain special characters, such as \\, \" and *" | |
echo "+ Bundle Identifier: The identifier of the application. Usually in the form of \"com.website.appname\" without quotes where com.website is a reversed domain name." | |
echo "+ Script To Execute: This is a shell script or binary and will be ran when you start your application." | |
echo "+ Application Icon: The icon to display on the application. Has to be in ICNS format. ICNS is a special format for macOS and it can be created with Image2icon from the App Store." | |
echo "+ Application Version: Version of the application, such as 1.0 or 3.1.2 ." | |
echo "+ Minimum System Version: Minimum macOS version to run the application, such as 10.12.6 (latest macOS Sierra) or 10.7.2 (OS X Lion)." | |
exit 0 | |
fi | |
read -p "Name of the application: " appname | |
read -p "Bundle identifier: " appidentifier | |
read -p "Script to execute when ran: " targetscript | |
read -p "Application icon (.icns): " targeticns | |
read -p "Application version: " vernum | |
read -p "Minimum system version (10.x.x): " minosnum | |
echo "" | |
echo "Creating \"${appname}.app\"..." | |
mkdir "./${appname}.app" | |
mkdir "./${appname}.app/Contents" | |
mkdir "./${appname}.app/Contents/MacOS" | |
mkdir "./${appname}.app/Contents/Resources" | |
echo "Creating Info.plist..." | |
echo '<?xml version="1.0" encoding="UTF-8"?>' > "./${appname}.app/Contents/Info.plist" | |
echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >> "./${appname}.app/Contents/Info.plist" | |
echo '<plist version="1.0">' >> "./${appname}.app/Contents/Info.plist" | |
echo '<dict>' >> "./${appname}.app/Contents/Info.plist" | |
echo '<key>CFBundleExecutable</key>' >> "./${appname}.app/Contents/Info.plist" | |
echo '<string>exec</string>' >> "./${appname}.app/Contents/Info.plist" | |
echo '<key>CFBundleIconFile</key>' >> "./${appname}.app/Contents/Info.plist" | |
echo '<string>Icon.icns</string>' >> "./${appname}.app/Contents/Info.plist" | |
echo '<key>CFBundlePackageType</key>' >> "./${appname}.app/Contents/Info.plist" | |
echo '<string>APPL</string>' >> "./${appname}.app/Contents/Info.plist" | |
echo '<key>CFBundleIdentifier</key>' >> "./${appname}.app/Contents/Info.plist" | |
echo "<string>${appidentifier}</string>" >> "./${appname}.app/Contents/Info.plist" | |
echo '<key>CFBundleName</key>' >> "./${appname}.app/Contents/Info.plist" | |
echo "<string>${appname}</string>" >> "./${appname}.app/Contents/Info.plist" | |
echo '<key>CFBundleShortVersionString</key>' >> "./${appname}.app/Contents/Info.plist" | |
echo "<string>${vernum}</string>" >> "./${appname}.app/Contents/Info.plist" | |
echo '<key>LSMinimumSystemVersion</key>' >> "./${appname}.app/Contents/Info.plist" | |
echo "<string>${minosnum}</string>" >> "./${appname}.app/Contents/Info.plist" | |
echo '</dict>' >> "./${appname}.app/Contents/Info.plist" | |
echo '</plist>' >> "./${appname}.app/Contents/Info.plist" | |
echo '#!/usr/bin/env bash' > "./${appname}.app/Contents/MacOS/exec" | |
echo '' >> "./${appname}.app/Contents/MacOS/exec" | |
echo '# This script is used to launch your script. Do' >> "./${appname}.app/Contents/MacOS/exec" | |
echo '# not modify this script unless you know what' >> "./${appname}.app/Contents/MacOS/exec" | |
echo '# you are doing.' >> "./${appname}.app/Contents/MacOS/exec" | |
echo '' >> "./${appname}.app/Contents/MacOS/exec" | |
echo "# Make the working directory the script's folder" >> "./${appname}.app/Contents/MacOS/exec" | |
echo 'cd "${0%/*}"' >> "./${appname}.app/Contents/MacOS/exec" | |
echo '' >> "./${appname}.app/Contents/MacOS/exec" | |
echo '# Run main_script in a new Terminal window' >> "./${appname}.app/Contents/MacOS/exec" | |
echo 'open ./main_script' >> "./${appname}.app/Contents/MacOS/exec" | |
echo "Copying the script inside the application..." | |
cp "${targetscript}" "./${appname}.app/Contents/MacOS/main_script" | |
chmod +x "./${appname}.app/Contents/MacOS/main_script" | |
chmod +x "./${appname}.app/Contents/MacOS/exec" | |
echo "Copying the icon inside the application..." | |
cp "${targeticns}" "./${appname}.app/Contents/Resources/Icon.icns" | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment