Skip to content

Instantly share code, notes, and snippets.

@Kvnbbg
Forked from HuangJiaLian/make_dmg.sh
Last active February 14, 2025 17:25
Show Gist options
  • Save Kvnbbg/84871ae4d642c2dd896e0423471b1b52 to your computer and use it in GitHub Desktop.
Save Kvnbbg/84871ae4d642c2dd896e0423471b1b52 to your computer and use it in GitHub Desktop.

Revisions

  1. Kvnbbg revised this gist Aug 30, 2023. 2 changed files with 62 additions and 0 deletions.
    1 change: 1 addition & 0 deletions make_dmg.sh
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@
    # ---------------------------------------
    # Clean up previous builds
    # ---------------------------------------

    echo "Cleaning up previous builds..."
    rm -rf build dist/*

    61 changes: 61 additions & 0 deletions setup_and_package.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    #!/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."

  2. Kvnbbg revised this gist Aug 30, 2023. 1 changed file with 33 additions and 25 deletions.
    58 changes: 33 additions & 25 deletions make_dmg.sh
    Original file line number Diff line number Diff line change
    @@ -1,42 +1,50 @@
    #!/bin/sh
    # Ref.: https://www.pythonguis.com/tutorials/packaging-pyqt5-applications-pyinstaller-macos-dmg/

    rm -rf build dist/*
    # 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

    #################################################
    # Create app file using pyinstaller
    #################################################
    # ---------------------------------------
    # Clean up previous builds
    # ---------------------------------------
    echo "Cleaning up previous builds..."
    rm -rf build dist/*

    pyinstaller --name 'Huanbu' \
    --icon 'huanbu.ico' \
    --windowed \
    # ---------------------------------------
    # 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:.' \
    huanbu.py

    main.py

    #################################################
    # Build the application bundle into a disk image
    #################################################
    # ---------------------------------------
    # Step 2: Convert the application bundle to a DMG (macOS disk image)
    # ---------------------------------------
    echo "Creating DMG installer..."

    # Create a folder (named dmg) to prepare our DMG in
    # (if it doesn't already exist).
    # Prepare the folder for DMG creation
    mkdir -p dist/dmg
    # Empty the dmg folder.
    rm -rf dist/dmg/*
    # Copy the app bundle to the dmg folder.
    cp -r "dist/Huanbu.app" dist/dmg
    # If the DMG already exists, delete it.
    test -f "dist/Huanbu.dmg" && rm "dist/Huanbu.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 "Huanbu" \
    --volicon "huanbu.ico" \
    --volname "CryptoSafePDF" \
    --volicon "CryptoSafePDF.ico" \
    --window-pos 200 120 \
    --window-size 600 300 \
    --icon-size 100 \
    --icon "Huanbu.app" 175 120 \
    --hide-extension "Huanbu.app" \
    --icon "CryptoSafePDF.app" 175 120 \
    --hide-extension "CryptoSafePDF.app" \
    --app-drop-link 425 120 \
    "dist/Huanbu.dmg" \
    "dist/CryptoSafePDF.dmg" \
    "dist/dmg/"

    echo "Packaging complete. You can find the DMG installer in the dist/ directory."
  3. Jie Huang created this gist Apr 2, 2022.
    42 changes: 42 additions & 0 deletions make_dmg.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/bin/sh
    # Ref.: https://www.pythonguis.com/tutorials/packaging-pyqt5-applications-pyinstaller-macos-dmg/

    rm -rf build dist/*

    #################################################
    # Create app file using pyinstaller
    #################################################

    pyinstaller --name 'Huanbu' \
    --icon 'huanbu.ico' \
    --windowed \
    --add-data='./strong_beat.wav:.' \
    --add-data='./sub_strong_beat.wav:.' \
    --add-data='./weak_beat.wav:.' \
    huanbu.py


    #################################################
    # Build the application bundle into a disk image
    #################################################

    # Create a folder (named dmg) to prepare our DMG in
    # (if it doesn't already exist).
    mkdir -p dist/dmg
    # Empty the dmg folder.
    rm -rf dist/dmg/*
    # Copy the app bundle to the dmg folder.
    cp -r "dist/Huanbu.app" dist/dmg
    # If the DMG already exists, delete it.
    test -f "dist/Huanbu.dmg" && rm "dist/Huanbu.dmg"
    create-dmg \
    --volname "Huanbu" \
    --volicon "huanbu.ico" \
    --window-pos 200 120 \
    --window-size 600 300 \
    --icon-size 100 \
    --icon "Huanbu.app" 175 120 \
    --hide-extension "Huanbu.app" \
    --app-drop-link 425 120 \
    "dist/Huanbu.dmg" \
    "dist/dmg/"