Mount disk image error - hdiutil: attach failed - Resource temporarily unavailable

I have this code below that works fine.

-- Mount Image
on mountSparsebundle(filePath)
	try
		-- Mount the sparsebundle
		do shell script "hdiutil attach " & quoted form of filePath
		--display dialog "Sparsebundle mounted successfully!" buttons {"OK"} default button "OK"
	on error errMsg
		--display dialog "Error: " & errMsg buttons {"OK"} default button "OK"
	end try
end mountSparsebundle

mountSparsebundle("/Path/to/file.sparsebundle")

Issue:

  • at times I get the following error:
tell current application
	do shell script "hdiutil attach '/Path/to/file.sparsebundle'"
		--> error "hdiutil: attach failed - Resource temporarily unavailable" number 1
end tell
  • If I manually try to open the file I get this error
    Screen Shot 2025-01-15 at 10.16.52 AM

Current Fix:

  • the fix is to reboot the computer.

Question:

  • how do I fix it so that I reboot is not required to mount this image? Is there some additional code that can be executed for this to mount?

and where does this sparsbundle come from? can it be in use by Time Machine at some point by any chance?

It is a time machine sparsebundle. Yes, it can.

I guess that’s your answer.

Plus… I’m sure you have your reasons to regularly mount Time Machine sparsebundles by script or manually. But that’s obviously not an intended or recommended use of TM data. I don’t know if it can be reliable. You may want to rethink the workflow that requires this step in the first place.

(I personally don’t have any experience with manual manipulation of TM sparsebundles though; maybe there are use cases I’m not aware of.)

Umm not really the answer. I’m looking to mount it and handle the error without rebooting.

Sparsebundle doesn’t update the date modified after a backup.

It appears that as long as you attempt to work with an active Time Machine sparsebundle, you’ll keep running into this error.

You can try some trickery like stopping TM before mounting the volume, then restart it. Or poll for this error in a loop until you’re able to mount it.

I have no idea if any of this can be successful

Is it a problem with your particular Time Machine operation, or is it a general Time Machine issue that all users experience? If the latter, then how do other users deal with it?