## New method to make the DS_Store file from scratch (on a Mac)
```
-./utils/install4j/mk_ds_store.sh
+./utils/install4j/mk_ds_store.sh --name Jalview [--bgimg ./utils/channels/release/image/jalview_dmg_background.png] [--output ./utils/channels/release/image/jalview_dmg_DS_Store]
```
A script that creates a new DMG with the top level items to be found in a Jalview Installer DMG, mounts the volume, then uses an AppleScript to adjust the background image, size and position of the icons, and appearance of the Finder window.
The .DS_Store is then copied out of the volume by the script, the volume unmounted, and all files (in /tmp) tidied up.
-To use it, the NAME (of the application, without the `.app` extension) should be set in the script (set to "Jalview"), and the background image that you want to use should be copied to your working directory as `background.png`.
+To use it, the NAME (of the application, without the `.app` extension) should be set in the script (set to "Jalview"), and the background image that you want to use should be copied to your working directory as `background.png` (or use the --bgimg option).
-Once it is run (only works on a Mac with osascript) it will leave a file Jalview_Installer-DS_Store in your working directory.
+Once it is run (only works on a Mac with osascript) it will leave a file Output-DS_Store in your working directory (or use the --output option).
+> This script borrows extensively from https://github.com/create-dmg/create-dmg
## Old manual method (possibly instructive)
#!/usr/bin/env bash
-NAME="Jalview"
+set -e
-TMPNAME="${NAME// /_}_Installer"
-APPNAME="${NAME}.app"
-DMG="${TMPNAME}.dmg"
+if [[ $(uname) != "Darwin" ]]; then
+ echo "Must be run on a Mac"
+ exit 1
+fi
+
+function usage() {
+ cat <<EOH
+Usage: $(basename "$0") --name "Your Application Name" [options]
+
+Options:
+ --name <name>
+ The application name (without '.app' extension) (mandatory)
+ --bgimg <pic.png>
+ Path to your background image (defaults to background.png)
+ --output <outputfile-dsstore>
+ The filename of the resullting .DS_Store (defaults to Output-DS_Store)
+ -h, --help
+ This help text
+
+EOH
+exit 0
+}
+
+# defaults
+BACKGROUNDIMG="background.png"
+OUTPUTNAME="Output-DS_Store"
+
+while [[ "${1:0:1}" = "-" ]]; do
+ case $1 in
+ --name)
+ NAME="$2"
+ shift; shift;;
+ --bgimg)
+ BACKGROUNDIMG="$2"
+ shift; shift;;
+ --output)
+ OUTPUTNAME="$2"
+ shift; shift;;
+ -h | --help)
+ usage;;
+ esac
+done
+
+if [[ -z "$NAME" ]]; then
+ echo "Must supply a --name Name argument"
+ exit 1
+fi
WDIR=$(pwd)
+# make a relative path absolute as we'll be cd-ing to /tmp
+if [[ "${BACKGROUNDIMG#/}" = "${BACKGROUNDIMG}" ]]; then
+ BACKGROUNDIMG="${WDIR}/${BACKGROUNDIMG}"
+fi
+
+# Note that VOLNAME is only for making the DS_Store file in. The final DMG can have a different Volume name
+# This temporary VOLNAME can be seen if you do `strings /Volume/Your DMG Name/.DS_Store` on the final .DS_Store
+# so we set this to something relatable to the application name.
+VOLNAME="${NAME// /_}_Installer"
+
+APPNAME="${NAME}.app"
+
+DMG="${VOLNAME}.dmg"
+# We set the Applications folder link to " " in the DMG
+APPLICATIONSFOLDERLINK=" "
+
+VOLDIR="/Volumes/${VOLNAME}"
+# The directory and filename this temporary volume is mounted from can be seen in `strings .DS_Store` so we move out
+# of userspace for generic and security reasons.
cd /tmp
-mkdir -p "$TMPNAME"
-cd "$TMPNAME"
+mkdir -p "$VOLNAME"
+cd "$VOLNAME"
mkdir "$APPNAME"
ln -s /Applications " "
mkdir .background
mkdir .fseventsd
-cp "${WDIR}/background.png" .background/background.png
+cp "$BACKGROUNDIMG" .background/background.png
cd /tmp
[ -e "$DMG" ] && rm "$DMG"
-hdiutil create -volname "$TMPNAME" -srcfolder "$TMPNAME" -size 1m -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$DMG"
+hdiutil create -volname "$VOLNAME" -srcfolder "$VOLNAME" -size 1m -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$DMG"
open "$DMG"
sleep 1
-VOL="/Volumes/${TMPNAME}"
-#osascript "${WDIR}/set_ds_store.applescript" "$TMPNAME" "$APPNAME"
-osascript - "$TMPNAME" "$APPNAME" <<EOF
+# WINX and WINY set the position on the display that the Finder window appears
+WINX=34
+WINY=55
+WINWIDTH=480
+WINHEIGHT=300
+# APPX and APPY are pixel position of the _centre_ of the app icon
+APPX=133
+APPY=124
+# APPLICATIONSX and APPLICATIONSY are pixel position of the _centre_ of the applications folder icon
+APPLICATIONSX=336
+APPLICATIONSY=124
+TEXTSIZE=14
+ICONSIZE=76
+
+osascript - "$VOLNAME" "$APPNAME" <<EOF
on run {volumeName, appName}
tell application "Finder"
tell disk (volumeName as string)
open
- set theXOrigin to 10
- set theYOrigin to 60
- set theWidth to 480
- set theHeight to 300
+ set theXOrigin to $WINX
+ set theYOrigin to $WINY
+ set theWidth to $WINWIDTH
+ set theHeight to $WINHEIGHT
set theBottomRightX to (theXOrigin + theWidth)
set theBottomRightY to (theYOrigin + theHeight)
set opts to the icon view options of container window
tell opts
- set icon size to 76
- set text size to 14
+ set icon size to $ICONSIZE
+ set text size to $TEXTSIZE
set label position to bottom
set arrangement to not arranged
end tell
set background picture of opts to file ".background:background.png"
- set position of item (appName as string) to {133, 124}
- set position of item " " to {336, 124}
+ set position of item (appName as string) to {$APPX, $APPY}
+ set position of item "$APPLICATIONSFOLDERLINK" to {$APPLICATIONSX, $APPLICATIONSY}
tell container window
set bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
end run
EOF
-DSSTORE="${VOL}/.DS_Store"
+# this 'sleep 3' isn't necessary but it gives you a chance to look at your handiwork!
+sleep 3
+
+DSSTORE="${VOLDIR}/.DS_Store"
until [ -e "$DSSTORE" ] && grep background.png "$DSSTORE"; do
sleep 1
echo "Waiting for \"$DSSTORE\" to update"
done
-SAVED_DSSTORE="${TMPNAME}-DS_Store"
-cp "$DSSTORE" "${WDIR}/${SAVED_DSSTORE}"
-echo "Created new .DS_Store as \"$SAVED_DSSTORE\""
+cp "$DSSTORE" "${WDIR}/${OUTPUTNAME}"
+echo "Created new .DS_Store as \"$OUTPUTNAME\""
-umount "$VOL"
+umount "$VOLDIR"
cd /tmp
rm "$DMG"
-rm -r "/tmp/${TMPNAME}"
+rm -r "/tmp/${VOLNAME}"
cd "$WDIR"