Skip to content

Kristapsp13/DMG-creator-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

DMG Creator Script

A professional macOS script that creates beautiful, installer-ready DMG files from your .app bundles with custom backgrounds, arrow graphics, and proper positioning.

Features

  • Custom Background - Gradient background with installation arrow
  • 📱 Professional Layout - App positioned on left, Applications link on right
  • 🎯 Material Design Arrow - Thick, modern arrow pointing from app to Applications
  • 🖼️ Custom Volume Icon - Uses your app's icon for the DMG volume
  • 📦 Version Support - Optional versioning in filename
  • 🔧 Multiple Fallbacks - Python PIL, ImageMagick, or basic backgrounds
  • 🍎 Native macOS Tools - Uses hdiutil, AppleScript, and SetFile

Requirements

  • macOS with developer tools (Xcode Command Line Tools)
  • Your .app bundle
  • Optional but recommended:
    • Python 3 with PIL/Pillow for best arrow quality
    • ImageMagick for fallback arrow creation

Installation

  1. Download the script:
curl -O https://github.com/Kristapsp13/DMG-creator-script.git/create_dmg.sh 
chmod +x create_dmg.sh
  1. Optional: Install Python PIL for best results:
pip3 install Pillow

Usage

Basic Usage

./create_dmg.sh YourApp.app

Creates: YourApp.dmg

With Version

./create_dmg.sh YourApp.app v2.0.0

Creates: YourApp_mac_v2.0.0.dmg

What Gets Created

The script generates a professional DMG with:

Layout

  • Window Size: 600x400 pixels
  • App Position: Left side (150, 200)
  • Applications Link: Right side (450, 200)
  • Icon Size: 128x128 pixels

Visual Elements

  • Background: Light gray to white gradient
  • Arrow: 12px thick Material Design style arrow
  • Arrow Style: Sharp triangle tip with rounded line caps
  • Volume Icon: Your app's icon (if available)

Files Included

  • Your .app bundle
  • Symbolic link to /Applications folder
  • Hidden background image (.background/background.png)
  • Custom .DS_Store for layout
  • Volume icon (.VolumeIcon.icns)

How It Works

1. Setup Phase

# Parse arguments and set up variables
APP_BUNDLE="$1"
VERSION="$2"
DMG_NAME="${APP_NAME}_mac_${VERSION}.dmg"  # With version
# or
DMG_NAME="${APP_NAME}.dmg"  # Without version

2. DMG Creation

# Create temporary 200MB DMG
hdiutil create -size 200m -fs HFS+ -volname "$VOLUME_NAME" "$TEMP_DMG"

# Mount it
hdiutil attach "$TEMP_DMG" -mountpoint "$MOUNT_POINT"

3. Content Setup

# Copy your app
cp -R "$APP_BUNDLE" "$MOUNT_POINT/"

# Create Applications symlink
ln -s /Applications "$MOUNT_POINT/Applications"

4. Background Creation

The script tries multiple methods in order:

Method 1: Python PIL (Best Quality)

# Creates 600x400 gradient background
# Draws 12px thick arrow with rounded caps
# Sharp triangle pointing to Applications

Method 2: ImageMagick (Good Quality)

magick -size 600x400 gradient:'#f5f5f5-#ffffff' \
       -stroke '#646464' -strokewidth 12 \
       -draw "line 240,200 352,200" \
       -draw "circle 240,200 246,200" \
       -draw "polygon 360,200 325,178 325,222"

Method 3: Fallback (Basic)

Uses macOS built-in tools to create simple background.

5. Layout Configuration

# AppleScript configures the DMG window
set current view of dmg_window to icon view
set icon size of icon_view_options to 128
set position of item "YourApp.app" to {150, 200}
set position of item "Applications" to {450, 200}
set background picture to file ".background:background.png"

6. Finalization

# Set volume icon
cp "$APP_BUNDLE/Contents/Resources/AppIcon.icns" "$MOUNT_POINT/.VolumeIcon.icns"

# Hide background folder
SetFile -a V "$MOUNT_POINT/.background"

# Unmount and compress
hdiutil detach "$MOUNT_POINT"
hdiutil convert "$TEMP_DMG" -format UDZO -imagekey zlib-level=9 -o "$DMG_NAME"

Customization

Arrow Styling

The arrow is designed with Material Design principles:

  • Thickness: 12px for bold visibility
  • Length: Shortened to not overlap with triangle
  • Style: Sharp triangle tip, rounded line caps
  • Color: Medium gray (#646464 / rgb(100,100,100))

Positions

Current layout positions:

app_x, app_y = 150, 200        # App icon position
apps_x, apps_y = 450, 200      # Applications position
arrow_start_x = app_x + 90     # Arrow starts closer to icon center
arrow_end_x = apps_x - 90      # Arrow ends closer to Applications

Background

  • Size: 600x400 pixels
  • Gradient: Light gray (#f5f5f5) to white (#ffffff)
  • Format: PNG with transparency support

Troubleshooting

"PIL not available"

Install Python Pillow:

pip3 install Pillow
# or
python3 -m pip install --user Pillow

"ImageMagick not available"

Install ImageMagick:

brew install imagemagick

"AppleScript configuration failed"

This is normal - the DMG will still work without custom appearance.

DMG won't mount

Check that your .app bundle is valid:

# Should show bundle structure
ls -la YourApp.app/Contents/

Arrow not showing

The script tries multiple methods. Check console output:

  • ✅ "Python PIL found" = Best quality arrow
  • ✅ "ImageMagick background created" = Good quality arrow
  • ⚠️ "Fallback background created" = No arrow, but DMG works

Technical Details

File Structure

YourApp.dmg (mounted)
├── YourApp.app/
├── Applications -> /Applications
├── .background/
│   └── background.png
├── .DS_Store
└── .VolumeIcon.icns

Dependencies

  • Required: macOS, hdiutil, SetFile, osascript
  • Optional: Python 3 + PIL, ImageMagick
  • Fallback: Built-in macOS image tools

Compatibility

  • macOS: 10.12+ (tested on modern versions)
  • Python: 3.6+ with PIL/Pillow
  • ImageMagick: v6 or v7 (auto-detected)

Examples

Software Release

./create_dmg.sh MyEditor.app v3.1.4
# Creates: MyEditor_mac_v3.1.4.dmg

Beta Version

./create_dmg.sh MyApp.app beta-2.0
# Creates: MyApp_mac_beta-2.0.dmg

Simple Release

./create_dmg.sh Calculator.app
# Creates: Calculator.dmg

License

This script is provided as-is for creating macOS application installers. Modify as needed for your distribution requirements.

About

DMG Creator Script

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages