-- 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
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?
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.)
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…