Suggestion: Place temporary disk images in $TMPDIR instead of the destination folder

To possibly avoid any filename collisions, my humble suggestion is to maybe place disk images that are in the process of being created inside of the $TMPDIR folder, and then add a custom, guid-like text string to the end of it.

For example:

$TMPDIR/MyDiskImage_dropdmgtemp-42a08354-c790-4a73-8274-965ec68c59fd.dmg

and if the filename is too long, truncate it (only for the temp file, though). For example, take a close look somewhat near the end of the filenames:

$TMPDIR/ccccccdssdftgsdfgsdfgdsfgdsfgdsfgdsfgdsfgdsfgdsfgdsgdsfggdfsdfggdfsdsgfgfdsdfgsdfgsdsgfgdsfgdfsccccccdssdftgsdfgsdfgdsfgdsfgdsfgdsfgdsfgdsfgdsfgdsgdsfggdfsdfggdfsdsgfgfdsdfgsdfgsdsgfgdsfgdfsdddddddddAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_dropdmgtemp-29c117b0-9ca9-43cb-a625-4614eecbff35.dmg

would get truncated to:

$TMPDIR/ccccccdssdftgsdfgsdfgdsfgdsfgdsfgdsfgdsfgdsfgdsfgdsgdsfggdfsdfggdfsdsgfgfdsdfgsdfgsdsgfgdsfgdfsccccccdssdftgsdfgsdfgdsfgdsfgdsfgdsfgdsfgdsfgdsfgdsgdsfggdfsdfggdfsdsgfgfdsdfgsdfgsdsgfgdsfgdfsdddddddddAaB_dropdmgtemp-29c117b0-9ca9-43cb-a625-4614eecbff35.dmg

Hope this makes sense and proves to be somewhat useful.

Forgot to add:

And then, after creation, the disk image would be moved to its specified destination.

Collisions with what? DropDMG already checks to make sure it’s using a unique filename. Using $TMPDIR is problematic because that volume might not have as much space as the chosen destination drive and could leak sensitive data because it’s encrypted differently (or not at all).

Good points, I didn’t think of those. The only reason I brought up the idea was because I wasn’t sure if DropDMG could/would accidentally overwrite a file with _temp.xxx at the end of its filename.

Nope, DropDMG won’t overwrite any files. It will make sure it doesn’t create two temp files with the same name, and leave any temp files created by other apps/scripts in place.