Create and Save a Disk Image

As mentioned earlier, the Shortcuts app has actions that allow you to create and mount disk images. Just out of general interest, I rewrote the shortcut in the prior post to use these actions, and the shortcut included below is the closest I could get. The differences are:

  • The Shortcuts Make Disk Image action has no compress option, although the default appears to be to compress the disk image.

  • When the encrypt option is selected, the user is separately prompted to enter a password. Also, the default is to save the password in the user’s keychain.

  • If the Mount Disk Image option is selected, the mounted image is shown in a Finder window (there’s no way to prevent this).

  • In my testing, the shortcut included below is noticeably sluggish when certain options are selected.

Create Disk Image (Shortcuts Version).shortcut (25.4 KB)

Ejecting several mounted disks or volumes is easily done by selecting them in a Finder window and clicking on Eject in the context menu. If this needs to be done on a regular basis, the following shortcut might be used.

Eject All Mounted Disks or Volumes (AppleScript).shortcut (22.8 KB)

FWIW, the paid Shortcutie app has an action that will do the same thing.

A third option involves parsing the output of the hdiutil -info command to get the relevant mounted disk images and then using the hdiutil -detach command to eject the disks. This is a bit involved and doesn’t seem to have any advantage over the AppleScript solution.

BTW, the first time I run the Eject All Mounted Disks or Volumes (AppleScript) shortcut on my Golden Gate computer, I get an error message. From that point on, the shortcut appears to work fine.

I recently noticed that hdiutil is deprecated in macOS 27.0.

I am a bit confused by this, because diskutil does not seem to have all the features of hdiutil.

For example, creating an HFS+ formatted DMG from the contents of a folder using diskutil is quite complicated and inconvenient.

I think I will try to use diskutil whenever possible, but I may have to keep using hdiutil for a few more years.

1 Like

IceFole. I agree wholeheartedly with your comments.

For me, the most significant issue is the inability of diskutil to create a disk image from multiple source files or folders. Just to make sure of this, I ran some simple tests to verify. Apple seems to be slow in removing deprecated commands and hopefully hdiutil will be around for a while.

diskutil Tests.shortcut (22.0 KB)