# Baut ein Installationsfenster, das aussieht wie eines. # # Von beiden Wegen benutzt — dem lokalen wie dem notarisierten —, damit das # Fenster in beiden Fällen dasselbe ist. # # Der Aufwand steckt nicht im Bild, sondern in der Reihenfolge: die # Fenstergröße, die Symbolplätze und das Hintergrundbild leben in der # `.DS_Store` des Abbilds. Die schreibt nur der Finder, und der schreibt sie # nur in ein **beschreibbares** Abbild. Also erst UDRW, dann einrichten, dann # zusammenpressen. # Erwartet: $1 App-Bundle, $2 Ziel-DMG, $3 Fenstertitel, $4 Arbeitsverzeichnis, # $5 Fassung (für die Fußzeile) make_pretty_dmg() { local app="$1" dmg="$2" volname="$3" work="$4" version="$5" local stage="$work/stage" temp="$work/rw.dmg" local root; root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" rm -rf "$stage" "$temp"; mkdir -p "$stage/.background" echo "→ Hintergrund zeichnen" xcrun swiftc -O "$root/Scripts/dmg-background.swift" -o "$work/dmg-bg" 2>/dev/null ONYX_VERSION="$version" "$work/dmg-bg" "$work/bg" # Ein TIFF mit beiden Auflösungen: als reines PNG wäre der Hintergrund auf # einem Retina-Bildschirm doppelt so groß wie das Fenster. tiffutil -cathidpicheck "$work/bg.png" "$work/bg@2x.png" \ -out "$stage/.background/background.tiff" >/dev/null cp -R "$app" "$stage/" ln -s /Applications "$stage/Applications" echo "→ Abbild anlegen" hdiutil create -volname "$volname" -srcfolder "$stage" -size 100m \ -fs HFS+ -format UDRW -ov "$temp" >/dev/null # Ein gleichnamiges Volume vorher abhängen. Sonst hängt macOS das neue als # „Onyx 1" ein, das AppleScript richtet weiter „Onyx" ein — und das fertige # Abbild sieht aus wie vorher, ohne dass irgendetwas fehlschlägt. while [ -d "/Volumes/$volname" ]; do hdiutil detach "/Volumes/$volname" -force -quiet || break sleep 1 done # Den tatsächlichen Einhängepunkt aus der Ausgabe lesen statt ihn zu raten. local mount mount=$(hdiutil attach "$temp" -nobrowse -noverify \ | grep -o '/Volumes/.*' | tail -1) [ -n "$mount" ] || { echo " (Abbild ließ sich nicht einhängen)"; return 1; } local disk; disk="$(basename "$mount")" sleep 2 echo "→ Fenster einrichten" osascript </dev/null || echo " (Finder nicht erreichbar — das Fenster bleibt schlicht)" tell application "Finder" tell disk "$disk" 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 -- 640 x 400 Punkte Inhalt; die Zahlen sind links, oben, rechts, unten. set the bounds of container window to {240, 140, 880, 540} set options to the icon view options of container window set arrangement of options to not arranged set icon size of options to 128 set text size of options to 12 set background picture of options to file ".background:background.tiff" set position of item "$(basename "$app")" of container window to {170, 196} set position of item "Applications" of container window to {470, 196} update without registering applications delay 1 close end tell end tell APPLESCRIPT # Der Finder schreibt die .DS_Store verzögert; ohne das Warten liegt im # fertigen Abbild die alte. sync sleep 2 hdiutil detach "$mount" -quiet || hdiutil detach "$mount" -force -quiet echo "→ Zusammenpressen" rm -f "$dmg" hdiutil convert "$temp" -format UDZO -imagekey zlib-level=9 -o "$dmg" >/dev/null rm -f "$temp" }