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?

I did troubleshoot this scenario but the system in question that used this TM image was not on.

I’m assuming when you mean active, it is currently doing.a time machine backup. It is not active when the script is running. The system in question that uses the TM image is not on, so no active use is occurring at that moment.

Doing some research there are posts that also show this occurring on this macOS (Monterey). No solution to the problem was posted.

While I don’t know if there’s any solution for this, it’s not related to AppleScript anyway. You may have better luck posting this question on stackoverflow.

I’ve gotten the script to successfully work. But it seems that mounting the TM image causes some issue that eventually doesn’t let the operating system mount the disk image until you reboot the computer again. Ideally I wouldn’t have to mount the disk image if the disk image date modified would update when the macOS does it’s TM for laptops or other computers. There doesn’t seem to be a resolution to date modified of disk image on macOS Monterey…