Can't set background image for DMG image file

Apologies for being off-AS topic but, I’m getting desperate. I’m trying to set a background image in the DMG image file that I use to distribute my applet. I use Finder’s “Show View Options >> Background >> Picture” function for the purpose. I have two problems.

The first is that the “Drag image here” method of adding a picture does not work. When I eject and reopen the image, the picture is not visible. The method which works is to click on “Drag image here” and use the open file dialog to find the desired image file. On ejecting and reopening, the image is visible. It seems that the background image is retained. Is that a bug in Finder ?

The second is that while the background image seems to be retained, it is not visible when the image file is opened on any other Mac. My development Mac runs Tahoe. I’ve have opened the DMG on Macs running Monterey and Sequoia. The background image is not visible. I don’t understand why.

The “Finder” method I’m using must be faulty. All sources I’ve found online explain that the background image should be inside a hidden “.background” folder. However, Finder in macOS Tahoe will not allow that folder to be created inside a DMG, even using an Admin user account. Also, that folder is not created when I used “Show View Options” to add a background image. I do wonder how Finder shows an image when it is not saved to anywhere I can find inside the DMG – is it cached ?

I have tried copying a “.background” folder across from another DMG (Firefox) to my DMG. That did not work – Finder does not show the background image on any Mac.

There must be a way of crafting a DMG background image which is visible on all versions of macOS. Can any one help ?

I don’t know if you’re interested in 3rd-party solutions but may I suggest DMG Canvas: DMG Canvas - Disk Image Layout and Building for macOS

The time you’ll save on wrestling with the built-in macOS ways may well worth the investment. At least that’s my experience. Plus it may have some sort of a free mode, not sure by now. I’ve been using it for years.

Thanks, yes, I might just have to give up and buy a 3rd party tool. DMG Canvas doesn’t seem to have a free version – US$30. Drop DMG is another famous tool that’s been around for many years.

No. As we all know, such things are stored in the .DS_Store files. But, I still don’t understand why the saved background is not visible on other Macs, Also, I think the background picture disappears if the “Show View Options” dialog is opened again. That seemed to happen a short while ago. The Show View Options dialog opens with the “Picture” button selected but the picture is gone and the .DS_Store file is suspiciously smaller. I think Finder is removing the picture – perhaps part of the bug I found in my first problem above.

1 Like

I am not sure how you are creating the DMG now, so I cannot say anything for certain.

Maybe we should first organize the steps.
I would like to confirm the steps for creating a DMG with a background image.

I think the workflow is something like this. Please let me know if I am missing anything.

1: Set the AppleShowAllFiles preference for com.apple.finder.
2: Create a temporary read/write DMG.(-format UDRW -fs HFS+)
3: Mount the DMG.
4: Copy the background image and volume icon onto the mounted volume.
5: In Finder, set the background image (icon view options to file “.background.png”).
6: Set the volume icon (using the SetFile command).
7: Unmount the volume.
8: Convert the DMG to read-only.

The temporary read/write DMG created in step 2 will be deleted after the final read-only DMG is created.

Does this workflow look correct? I think I may be missing something.

One more point: when unmounting in step5, the Finder window for the volume needs to already be in Icon View.

If the background image or Icon View settings do not seem to be applied correctly, running an update command after step 5 and before unmounting may help.

		tell application "Finder"
			update PATH_TO_MOUNTED_VOLUME_ALIAS
		end tell

Thanks for all that. I’m using Disk Utility. I don’t understand most of your workflow:

How do you do that ?

What file names do you use ? Is the volume icon necessary ?

I think that’s what I’ve been doing with “Show View Options”, except that there is no file of that name. Did you give it that name or did Finder or macOS ?

I guess you mean to set the volume icon as a custom icon for the DMG. Is that necessary for the background image workflow to work ? Instead of using SetFile why not just use GetInfo in Finder ?

Step 5 is crucial. The background picture works on my Mac running Tahoe, but is not visible on another Mac. Also, there is no “.background” file.

Thanks.

The Finder setting AppleShowAllFiles controls whether hidden files are visible or not.

If you use Finder to copy files (for example, the .background folder or other hidden files), I think this setting is necessary.

#ZSH exec terminal
# Show all files
/usr/bin/defaults write com.apple.finder AppleShowAllFiles -bool true
/usr/bin/killall Finder

# Hide hidden files
/usr/bin/defaults write com.apple.finder AppleShowAllFiles -bool false
/usr/bin/killall Finder

not visible on another Mac

If backward compatibility is important, I think the DMG should be created using the Mac OS Extended (Journaled) format.
Is your DMG using that format?


With the mounted Mac OS Extended (Journaled) read/write DMG in the state shown in the screenshot above, and after copying the hidden dot file .background.png to the root of the mounted volume, how about setting it like this?

Please give it a try.

#!/usr/bin/env osascript
#coding: utf-8
use AppleScript version "2.8"
use scripting additions


set aliasMountedVolume to (choose folder with prompt "Choose Mounted Volume" without multiple selections allowed) as alias


tell application "Finder"
	activate
	set refFinderWindow to make new Finder window
	tell refFinderWindow
		set numWindowID to id
	end tell
	delay 1
	tell window id numWindowID
		set target to aliasMountedVolume
		set position to {50, 50}
		set bounds to {30, 55, 720, 620}
		set statusbar visible to false
		set toolbar visible to false
		set current view to icon view
		set arrangement of its icon view options to arranged by name
		set background picture of its icon view options to file ".background.png"
	end tell
end tell
delay 1
tell application "Finder"
	update aliasMountedVolume
end tell
delay 1
tell application "Finder"
	tell window id numWindowID to close
end tell
delay 1
tell application "Finder"
	activate
	set refFinderWindow to make new Finder window
	tell refFinderWindow
		set numWindowID to id
	end tell
	tell window id numWindowID
		set target to aliasMountedVolume
		set position to {50, 50}
		set bounds to {30, 55, 720, 620}
		set statusbar visible to false
		set toolbar visible to false
		set current view to icon view
		set arrangement of its icon view options to arranged by name
		set background picture of its icon view options to file ".background.png"
	end tell
end tell
tell application "Finder"
	update aliasMountedVolume
end tell

The same operation is done twice because sometimes the first one is not applied correctly.
It should normally work with only one time.


The volume icon is optional. It is not required.

When Finder’s update command is executed, it may remove hidden files on the mounted volume that Finder considers unnecessary.

So, after the background image has been configured, copy the hidden dot file .VolumeIcon.icns to the mounted volume, and then set it with:

#ZSH exec terminal
/usr/bin/SetFile -a C "/Volumes/SOME_APP"

Just in case: you can toggle hidden file visibility in the Finder by pressing Cmd-Shift-. (period).

Just in case: you can toggle hidden file visibility in the Finder by pressing Cmd-Shift-. (period).

Yes, I know that method. It is very useful.

However, in this case it cannot be used because Finder returns an error.

I think it could probably be done with System Events instead, but then I would first need to check the current setting and decide whether it should be changed or not.

So, for this particular case, I don’t think it is the best approach.

set background picture of its icon view options to file ".background.png"

The Cmd-Shift-. (period) shortcut can sometimes change the visibility of hidden files in the Finder window without changing the AppleShowAllFiles value in com.apple.finder.plist.

It may be possible to detect the current state using NSUserDefaults, but I think it is not easy to determine which state Finder is actually in.

However, if showing hidden files is simply treated as a prerequisite before the script runs (for example, before setting the Finder background picture), then there is no need for the script to change the setting itself.

That may actually be a good idea. Thanks!

1 Like