之前有介绍过 利用 keta.app 压缩工具来制作dmg安装文件
keak 压缩工具可以直接将目录制作成dmg文件。只需要把目录拖放到 keka 就可以轻松实现,目录里可以做一个Application的链接这样就可以利用dmg来分发开发好的macos 的 app了。为了更简化操作,还可以写成sh脚本。# 建一个用来破app的目录mkdir target# 将app复制进目录mv test.app target#将在目录下建Application 链接ln -s /Applications target/Application
这次再介绍用 create-dmg 开源脚本,相对而言更加适合脚本的方式使用。
下面是安装和使用说明。
直接 brew install create-dmg 就能安装。
xulong@xulongdeMac-mini ~ % brew install create-dmg
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/create-dmg-1.0.10.a
#=#=#
curl: (22) The requested URL returned error: 404
使用例子
rm -rf *.c *.so build/
#dist目录下的 工资条帮.app 打包为 wxWorkHelper_setup.dmg
test -f dist/wxWorkHelper_setup.dmg && rm -f wxWorkHelper_setup.dmg
create-dmg --volname 工资条帮 \
--window-pos 200 120 \
--window-size 800 400 \
--volicon appicon.icns \
--icon-size 100 \
--icon 工资条帮.app 200 190 \
--hide-extension 工资条帮.app \
--app-drop-link 600 185 \
dist/wxWorkHelper_setup.dmg \
dist/工资条帮.app
打包完成dmg后,打开dmg就能安装了。
create-dmg
A shell script to build fancy DMGs.
Status and contribution policy
Create-dmg is mostly maintained by @aonez and the contributors who send pull requests. The project home page is GitHub - create-dmg/create-dmg: A shell script to build fancy DMGs.
We will merge any pull request that adds something useful and does not break existing things.
If you're an active user and want to be a maintainer, or just want to chat, please ping us on Gitter at gitter.im/create-dmg/Lobby, or email Andrew directly.
Create-dmg was originally created by Andrey Tarantsov. In May 2020 Andrew Janke helped vastly with the project.
Installation
- You can install this script using Homebrew: brew install create-dmg
- You can download the latest release and install it from there: make install
- You can also clone the entire repository and run it locally from there: git clone https://github.com/create-dmg/create-dmg.git
Usage
create-dmg [options ...] <output_name.dmg> <source_folder>
All contents of source_folder will be copied into the disk image.
Options:
- --volname <name>: set volume name (displayed in the Finder sidebar and window title)
- --volicon <icon.icns>: set volume icon
- --background <pic.png>: set folder background image (provide png, gif, jpg)
- --window-pos <x> <y>: set position the folder window
- --window-size <width> <height>: set size of the folder window
- --text-size <text_size>: set window text size (10-16)
- --icon-size <icon_size>: set window icons size (up to 128)
- --icon <file_name> <x> <y>: set position of the file's icon
- --hide-extension <file_name>: hide the extension of file
- --custom-icon <file_name|custom_icon|sample_file> <x> <y>: set position and -tom icon
- --app-drop-link <x> <y>: make a drop link to Applications, at location x, y
- --ql-drop-link <x> <y>: make a drop link to /Library/QuickLook, at location x, y
- --eula <eula_file>: attach a license file to the dmg
- --rez <rez_path>: specify custom path to Rez tool used to include license file
- --no-internet-enable: disable automatic mount©
- --format: specify the final image format (UDZO|UDBZ|ULFO|ULMO) (default is UDZO)
- --add-file <target_name> <file|folder> <x> <y>: add additional file or folder (can be used multiple times)
- --disk-image-size <x>: set the disk image size manually to x MB
- --hdiutil-verbose: execute hdiutil in verbose mode
- --hdiutil-quiet: execute hdiutil in quiet mode
- --bless: bless the mount folder (deprecated, needs macOS 12.2.1 or older, #127)
- --codesign <signature>: codesign the disk image with the specified signature
- --notarize <credentials>: notarize the disk image (waits and staples) with the keychain stored credentials For more information check Apple's documentation
- --skip-jenkins: skip Finder-prettifying AppleScript, useful in Sandbox and non-GUI environments, #72
- --sandbox-safe: hdiutil with sandbox compatibility, do not bless and do not execute the cosmetic AppleScript
- --version: show tool version number
- -h, --help: display the help
Example
#!/bin/sh test -f Application-Installer.dmg && rm Application-Installer.dmg create-dmg \ --volname "Application Installer" \ --volicon "application_icon.icns" \ --background "installer_background.png" \ --window-pos 200 120 \ --window-size 800 400 \ --icon-size 100 \ --icon "Application.app" 200 190 \ --hide-extension "Application.app" \ --app-drop-link 600 185 \ "Application-Installer.dmg" \ "source_folder/"
See the examples
folder in the source tree for more examples.
GitHub - create-dmg/create-dmg: A shell script to build fancy DMGs