본문 바로가기
PyQt5_

Creating a macOS Disk Image Installer

by 자동매매 2023. 3. 13.

39. Creating a macOS Disk Image

Installer

In a previous chapter we used PyInstaller to build a macOS .app file from our application. Opening this .app will run your application, and you can technically distribute it to other people as it is. However, there’s a catch — macOS .app files are actually just folders with a special extension. This means they aren’t suited for sharing as they are — end users would need to download all the individual files inside the folder.

The solution is to distribute the .app inside a Zip .zip or disk image .dmg file. Most commercial software uses disk images since you can also include a shortcut to the user’s Applications folder, allowing them to drag the application over in a single move. This is now so common than many users would be quite confused to be faced with anything else. Let’s just stick with the convention.

ë

If you’re impatient, you can download the Example macOS Disk

Image first.

create-dmg

It’s relatively straightforward to create DMG files yourself, but I’d recommend starting by using the tool create-dmg which can be installed from Homebrew. This tool installs as a simple command-line tool, which you can call passing in a few parameters to generate your DMG installer.

You can install the create-dmg package with Homebrew.

brew install create-dmg

Once installed you have access to the create-dmg bash script. Below is a subset of the options, which can be displayed by running create-dmg --help

--volname : set volume name (displayed in the Finder sidebar and

window title)

--volicon : set volume icon

--background : set folder background image (provide png, gif,

jpg)

--window-pos : set position the folder window

--window-size : set size of the folder window

--text-size : set window text size (10-16)

--icon-size : set window icons size (up to 128)

--icon : set position of the file's icon

--hide-extension : hide the extension of file

--app-drop-link : make a drop link to Applications, at location

x, y

--eula : attach a license file to the dmg

--no-internet-enable: disable automatic mount©

--format: specify the final image format (default is UDZO)

--add-file <file|folder> : add additional file or</file|folder>

folder (can be used multiple times)

--disk-image-size : set the disk image size manually to x MB

--version: show tool version number

-h, --help: display the help

Z

Volume is a technical name for a disk, so Volume name is the

name you want to give to the disk image (DMG) itself.

Together with the options given above, you need to specify the output name for your DMG file and an input folder — the folder containing your .app generated by PyInstaller.

Below we’ll use create-dmg to create an installer DMG for our Hello World application. We’re only using some of the available options here — setting the name & icon of the disk volume, positioning and sizing the window, setting the icon for our app and adding the /Applications drop destination link. This is the bare minimum you will likely want to set for your own applications, and you can customize it further yourself if you prefer.

Since create-dmg copies all files in the specified folder into the DMG you’ll need to

ensure that your .app file is in a folder by itself. I recommend creating a folder dmg and copying the built .app bundle into it into it. Below I’ve created a small script to perform the packaging, including a test to check for and remove any previously-built DMG files.

Listing 260. packaging/installer/mac/makedmg.sh

#!/bin/sh

test -f "Hello World.dmg" && rm "Hello World.dmg"

test -d "dist/dmg" && rm -rf "dist/dmg"

# Make the dmg folder & copy our .app bundle in.

mkdir -p "dist/dmg"

cp -r "dist/Hello World.app" "dist/dmg"

# Create the dmg.

create-dmg \

--volname "Hello World" \

--volicon "icons/icon.icns" \

--window-pos 200 120 \

--window-size 800 400 \

--icon-size 100 \

--icon "Hello World.app" 200 190 \

--hide-extension "Hello World.app" \

--app-drop-link 600 185 \

"Hello World.dmg" \

"dist/dmg/"

Save this into the root of your project named build-dmg.sh and then make it executable with.

$ chmod +x build-dmg.sh

Then execute the script to build the package.

$ ./build-dmg.sh

The create-dmg process will run and a DMG file will be created in the current folder, matching the name you’ve given for the output file (the second to last

argument, with the .dmg extension). You can now distribute the resulting DMG file to other macOS users!

Figure 265. The resulting Disk Image showing our .app bundle and the Applications shortcut. Drag the app across to install.

ë

For more information on create-dmg see the documentation on

Github.

'PyQt5_' 카테고리의 다른 글

Translating C++ Examples to Python.  (0) 2023.03.13
Creating a Linux Package with  (0) 2023.03.13
Creating a Windows installer with InstallForge  (0) 2023.03.13
Packaging with PyInstaller  (0) 2023.03.13
Working with command-line arguments  (0) 2023.03.13

댓글