Skip to content

Instantly share code, notes, and snippets.

@matagus
Forked from Kvnbbg/make_dmg.sh
Created February 11, 2024 19:05
Show Gist options
  • Save matagus/da66e2c04a1598e3abf4d81ee19c69f7 to your computer and use it in GitHub Desktop.
Save matagus/da66e2c04a1598e3abf4d81ee19c69f7 to your computer and use it in GitHub Desktop.
Two steps to turn a Python file to a macOS installer
#!/bin/sh
# References
# https://www.pythonguis.com/tutorials/packaging-pyqt5-applications-pyinstaller-macos-dmg/
# https://medium.com/@jackhuang.wz/in-just-two-steps-you-can-turn-a-python-script-into-a-macos-application-installer-6e21bce2ee71
# ---------------------------------------
# Clean up previous builds
# ---------------------------------------
echo "Cleaning up previous builds..."
rm -rf build dist/*
# ---------------------------------------
# Step 1: Convert Python script to an application bundle
# ---------------------------------------
echo "Converting Python script to macOS app bundle..."
# The following command will create a standalone .app from your Python script
pyinstaller --name 'CryptoSafePDF' \
--icon 'CryptoSafePDF.ico' \
--windowed \
--add-data='./strong_beat.wav:.' \
--add-data='./sub_strong_beat.wav:.' \
--add-data='./weak_beat.wav:.' \
main.py
# ---------------------------------------
# Step 2: Convert the application bundle to a DMG (macOS disk image)
# ---------------------------------------
echo "Creating DMG installer..."
# Prepare the folder for DMG creation
mkdir -p dist/dmg
rm -rf dist/dmg/*
cp -r "dist/CryptoSafePDF.app" dist/dmg
# Create the DMG
# Ensure you have 'create-dmg' installed. If not, install using 'brew install create-dmg'
create-dmg \
--volname "CryptoSafePDF" \
--volicon "CryptoSafePDF.ico" \
--window-pos 200 120 \
--window-size 600 300 \
--icon-size 100 \
--icon "CryptoSafePDF.app" 175 120 \
--hide-extension "CryptoSafePDF.app" \
--app-drop-link 425 120 \
"dist/CryptoSafePDF.dmg" \
"dist/dmg/"
echo "Packaging complete. You can find the DMG installer in the dist/ directory."
#!/bin/bash
# CryptoSafePDF Setup and Packaging Script for macOS
# 1. Install Homebrew (if not installed)
if ! command -v brew &>/dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Homebrew already installed."
fi
# 2. Install create-dmg
if ! brew list create-dmg &>/dev/null; then
echo "Installing create-dmg..."
brew install create-dmg
else
echo "create-dmg already installed."
fi
# 3. Install pyinstaller
if ! pip list | grep pyinstaller &>/dev/null; then
echo "Installing pyinstaller..."
pip install pyinstaller
else
echo "pyinstaller already installed."
fi
# 4. Clean up previous builds
echo "Cleaning up previous builds..."
rm -rf build dist/*
# 5. Convert Python script to an application bundle
echo "Converting Python script to macOS app bundle..."
pyinstaller --name 'CryptoSafePDF' \
--icon 'CryptoSafePDF.ico' \
--windowed \
--add-data='./strong_beat.wav:.' \
--add-data='./sub_strong_beat.wav:.' \
--add-data='./weak_beat.wav:.' \
main.py
# 6. Create the DMG installer
echo "Creating DMG installer..."
mkdir -p dist/dmg
rm -rf dist/dmg/*
cp -r "dist/CryptoSafePDF.app" dist/dmg
create-dmg \
--volname "CryptoSafePDF" \
--volicon "CryptoSafePDF.ico" \
--window-pos 200 120 \
--window-size 600 300 \
--icon-size 100 \
--icon "CryptoSafePDF.app" 175 120 \
--hide-extension "CryptoSafePDF.app" \
--app-drop-link 425 120 \
"dist/CryptoSafePDF.dmg" \
"dist/dmg/"
echo "Packaging complete. You can find the DMG installer in the dist/ directory."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment