Saya akhirnya berhasil dalam proyek saya sendiri (yang kebetulan berada di Xcode). Menambahkan 3 skrip ini ke fase build Anda akan secara otomatis membuat Disk Image untuk produk Anda yang bagus dan rapi. Yang harus Anda lakukan adalah membangun proyek Anda dan DMG akan menunggu di folder produk Anda.
Script 1 (Buat Temp Disk Image):
#!/bin/bash
#Create a R/W DMG
dir="$TEMP_FILES_DIR/disk"
dmg="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.temp.dmg"
rm -rf "$dir"
mkdir "$dir"
cp -R "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app" "$dir"
ln -s "/Applications" "$dir/Applications"
mkdir "$dir/.background"
cp "$PROJECT_DIR/$PROJECT_NAME/some_image.png" "$dir/.background"
rm -f "$dmg"
hdiutil create "$dmg" -srcfolder "$dir" -volname "$PRODUCT_NAME" -format UDRW
#Mount the disk image, and store the device name
hdiutil attach "$dmg" -noverify -noautoopen -readwrite
Script 2 (Set Script Properti Jendela):
#!/usr/bin/osascript
#get the dimensions of the main window using a bash script
set {width, height, scale} to words of (do shell script "system_profiler SPDisplaysDataType | awk '/Main Display: Yes/{found=1} /Resolution/{width=$2; height=$4} /Retina/{scale=($2 == \"Yes\" ? 2 : 1)} /^ {8}[^ ]+/{if(found) {exit}; scale=1} END{printf \"%d %d %d\\n\", width, height, scale}'")
set x to ((width / 2) / scale)
set y to ((height / 2) / scale)
#get the product name using a bash script
set {product_name} to words of (do shell script "printf \"%s\", $PRODUCT_NAME")
set background to alias ("Volumes:"&product_name&":.background:some_image.png")
tell application "Finder"
tell disk product_name
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {x, y, (x + 479), (y + 383)}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 128
set background picture of theViewOptions to background
set position of item (product_name & ".app") of container window to {100, 225}
set position of item "Applications" of container window to {375, 225}
update without registering applications
close
end tell
end tell
Pengukuran di atas untuk pekerjaan jendela untuk proyek saya secara khusus karena ukuran gambar latar belakang saya dan resolusi ikon; Anda mungkin perlu mengubah nilai-nilai ini untuk proyek Anda sendiri.
Script 3 (Buat Skrip Gambar Disk Akhir):
#!/bin/bash
dir="$TEMP_FILES_DIR/disk"
cp "$PROJECT_DIR/$PROJECT_NAME/some_other_image.png" "$dir/"
#unmount the temp image file, then convert it to final image file
sync
sync
hdiutil detach /Volumes/$PRODUCT_NAME
rm -f "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg"
hdiutil convert "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.temp.dmg" -format UDZO -imagekey zlib-level=9 -o "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg"
rm -f "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.temp.dmg"
#Change the icon of the image file
sips -i "$dir/some_other_image.png"
DeRez -only icns "$dir/some_other_image.png" > "$dir/tmpicns.rsrc"
Rez -append "$dir/tmpicns.rsrc" -o "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg"
SetFile -a C "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg"
rm -rf "$dir"
Pastikan file gambar yang Anda gunakan ada di direktori $ PROJECT_DIR / $ PROJECT_NAME /!