5 if [[ $(uname) != "Darwin" ]]; then
6 echo "Must be run on a Mac"
12 Usage: $(basename "$0") --name "Your Application Name" [options]
16 The application name (without '.app' extension) (mandatory)
18 Path to your background image (defaults to background.png)
19 --output <outputfile-dsstore>
20 The filename of the resullting .DS_Store (defaults to Output-DS_Store)
29 BACKGROUNDIMG="background.png"
30 OUTPUTNAME="Output-DS_Store"
32 while [[ "${1:0:1}" = "-" ]]; do
48 if [[ -z "$NAME" ]]; then
49 echo "Must supply a --name Name argument"
54 # make a relative path absolute as we'll be cd-ing to /tmp
55 if [[ "${BACKGROUNDIMG#/}" = "${BACKGROUNDIMG}" ]]; then
56 BACKGROUNDIMG="${WDIR}/${BACKGROUNDIMG}"
59 # Note that VOLNAME is only for making the DS_Store file in. The final DMG can have a different Volume name
60 # This temporary VOLNAME can be seen if you do `strings /Volume/Your DMG Name/.DS_Store` on the final .DS_Store
61 # so we set this to something relatable to the application name.
62 VOLNAME="${NAME// /_}_Installer"
67 # We set the Applications folder link to " " in the DMG
68 APPLICATIONSFOLDERLINK=" "
70 VOLDIR="/Volumes/${VOLNAME}"
71 # The directory and filename this temporary volume is mounted from can be seen in `strings .DS_Store` so we move out
72 # of userspace for generic and security reasons.
77 ln -s /Applications " "
80 cp "$BACKGROUNDIMG" .background/background.png
82 [ -e "$DMG" ] && rm "$DMG"
83 hdiutil create -volname "$VOLNAME" -srcfolder "$VOLNAME" -size 1m -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$DMG"
88 # WINX and WINY set the position on the display that the Finder window appears
93 # APPX and APPY are pixel position of the _centre_ of the app icon
96 # APPLICATIONSX and APPLICATIONSY are pixel position of the _centre_ of the applications folder icon
102 osascript - "$VOLNAME" "$APPNAME" <<EOF
103 on run {volumeName, appName}
104 tell application "Finder"
105 tell disk (volumeName as string)
108 set theXOrigin to $WINX
109 set theYOrigin to $WINY
110 set theWidth to $WINWIDTH
111 set theHeight to $WINHEIGHT
113 set theBottomRightX to (theXOrigin + theWidth)
114 set theBottomRightY to (theYOrigin + theHeight)
116 tell container window
117 set current view to icon view
118 set toolbar visible to false
119 set statusbar visible to false
120 set pathbar visible to false
121 set bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY + 220}
122 set statusbar visible to false
123 set position of every item to {100, theBottomRightY + 150}
126 set opts to the icon view options of container window
128 set icon size to $ICONSIZE
129 set text size to $TEXTSIZE
130 set label position to bottom
131 set arrangement to not arranged
134 set background picture of opts to file ".background:background.png"
136 set position of item (appName as string) to {$APPX, $APPY}
137 set position of item "$APPLICATIONSFOLDERLINK" to {$APPLICATIONSX, $APPLICATIONSY}
139 tell container window
140 set bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
152 # this 'sleep 3' isn't necessary but it gives you a chance to look at your handiwork!
155 DSSTORE="${VOLDIR}/.DS_Store"
156 until [ -e "$DSSTORE" ] && grep background.png "$DSSTORE"; do
158 echo "Waiting for \"$DSSTORE\" to update"
161 cp "$DSSTORE" "${WDIR}/${OUTPUTNAME}"
162 echo "Created new .DS_Store as \"$OUTPUTNAME\""
167 rm -r "/tmp/${VOLNAME}"