Simple DMG Customization

I want to include a script in my Swift app to apply a simple customization of a DMG that it creates

Something very simple (similar but not identical to this)

The created DMG has a single APP file (not a folder like in the above image), that needs to be dragged to Applications. All I really need it to

a) Postion and size the App Icon
b) Position and include the “Application Folder” icon
c) add an arrow
d) Optional place some text above and/or below

I know it has to be AppleScript, and all I supply is the name of the App file

It’s been quite a few moons since I did any of this manually but if I recall correctly…

a) Size is based upon the Finder icon size for the window. Don’t recall position but I think this is also Finder based.
b & c) Application folder is just a Finder alias to /Applications. The arrow is a result of this as well.
d) The text above/below is embedded into the background image (/.background folder in disk image with image being a TIFF.

Others might have more info on this as I don’t think any of this was documented very well by Apple and ended up being tribal knowledge.

If you’re not entirely dead set on doing everything from scratch, I highly recommend DMG Canvas which is also scriptable so that you can put things into a build script or CI/CD pipeline. There’s also DropDMG which is also very capable in this regard. Both are $25 for a license.

2 Likes

I’d guess you can / could find something in this
Its a post build script for Xojo that builds a DMG
Cant say more than that an whether it applies custom icons etc

EDIT : I see I neglected to post the link :stuck_out_tongue:

The only custom icon I need is “Applications Folder” and if I recall the DMG gets the actual icon from find.

I am dead-set on doing this from scratch, as i need the process embedded in another

Thing is if I recall thats an alias to the Applications folder not just a custom icon

The script from Jürg MIGHT show you how to create that so you can then do the same

The actual script is at

EDIT : fix typo in Jürg’s name
Apologies

1 Like

You’ll find everything in that example script. Thanks to Norman for posting the link.

Your c) and d) is just the background image.

2 Likes

Anyone see what is wrong? Because I do not

tell application "Finder"
		tell disk "MY_DMG"
				open
				tell container window
					set current view to icon view
					set toolbar visible to false
					set statusbar visible to false
					set x to 100
					set y to 100
					set w to 200
					set h to 200
					set bounds to {x, y, x + w, y + h}
				end tell
				set opts to icon view options of container window
				tell opts
						set shows icon preview to false
						set shows item info to false
						set icon size to 128
						set text size to 40
						set arrangement to not arranged
						set label position to bottom
						set background color to {1,0,0}
				end tell
		end tell
	update disk "MY_DMG"
	delay 5
end tell
error:  {
    NSAppleScriptErrorAppName = Finder;
    NSAppleScriptErrorBriefMessage = "AppleEvent handler failed.";
    NSAppleScriptErrorMessage = "Finder got an error: AppleEvent handler failed.";
    NSAppleScriptErrorNumber = "-10000";
    NSAppleScriptErrorRange = "NSRange: {404, 9}";
}

this is in my entitlement file

<key>com.apple.security.automation.apple-events</key>
	<true/>

and this is in the info.plist

<key>NSAppleEventsUsageDescription</key>
<string>Customize DMG</string>

looks like for some reason THAT line borked it

seems max size allowed is 16

anyone know the correct AppleScript syntax for this line

‘’’
set background picture of opts to file <?????>
‘’’

the background image is stored in the DGM as

.background/image.jpg

FYI… it needs to be a JPG, because I want in stored in the bundle of the app the is CREATING the DMG, and you cannot access the Assets Catalog, and putting a PNG has all kinds of fork/resouce issues for some reason

Just guessing but maybe

set background picture of opts to file /Volumes/MountedName/.background/image.jpg

Darn… nope…

set background picture of opts to file ":Volumes:XXXX_A:.background:dmg_bg2.jpg"
NSAppleScriptErrorMessage = "Finder got an error: Can\U2019t set file \":Volumes:XXXX_A:.background:dmg_bg2.jpg\" of disk \"XXXX_A\" to file \":Volumes:XXXX_A:.background:dmg_bg2.jpg\" of disk \"XXXX_A\".";


I also tried it by NOT changing the slashes to colons

Try getting rid of the full path and just use “.background:image.jpg” where “.background” is a folder.

yup… this worked (finally)

set background picture of opts to file ".background:dmg_bg2.jpg"