Bug Script to mount image > lanch app, and unmount image when quit app


I’m trying to make a script to do that :

1 - Mount image (a sparse bundle image)
2 - When mounted, launch app (Lightroom)
3 - When I’m quitting the app (LightRoom), just unmount the image.

To do that, I’m trying to use a script found here :

And, after changing some parameters, steps 1 and 2 are working well. But step 3 doesn’t work : when I quit Lightroom, the image is not unmounted.

The script :

property diskname : "Catalogue-Lightroom"
property diskpath : "Données Aurélie:Permanent:Catalogue-Lightroom.sparsebundle"
property itemname : "Macintosh HD:Applications:Adobe Photoshop Lightroom 4.app"
property appname : "Adobe Photoshop Lightroom 4.app"

on run
	tell application "Finder"
		if not (exists the disk diskname) then
			do shell script ("hdiutil attach " & quoted form of ¬
				POSIX path of (diskpath as string) & " -mount required")
			repeat until name of every disk contains diskname
				delay 1
			end repeat
		end if
		open item itemname
	end tell
	delay 5
end run
-- remainder based on hint by puffyn at macosxhints.com:
-- hint named "Quick Applescript to Mount Disk Image"
-- shell script to get devname by Dale Mox with fixes by jbc 
on idle
	set devname to do shell script "mount | grep " & diskname & ¬
		" | cut -f1-1 -d \" \" | cut -f3-3 -d \"/\""
	tell application "Finder"
		if not (exists the disk diskname) then
			set x to the name of every process
			if appname is not in x then
				do shell script ("hdiutil unmount /Volumes/" & diskname & " -force")
				do shell script ("hdiutil detach " & devname & " -force")
				tell me to quit
			end if
		end if
	end tell
	return 2
end idle

In addition, I would be able do two special things :

A - to mount an image wish is on a network volume, with this kind of adresse :
“afp://Mac mini de Aurélie._afpovertcp._tcp.local/Données Aurélie/Permanent/Catalogue-Lightroom.sparsebundle”
Is it possible ?

B - to get a error message if the image is already mounted by someone else on an another computer. Is it possible too ? I thing that diskutil have this kind of message, but how to grab it into the script ?

Thanks :slight_smile:

Finally, in my last post, I need to find a solution only for the A point. In fact, I already got the good error message when image is already mounted by another computer.

But I can’t mount image on network, and automatically unmount doesn’t work. Any help ? :slight_smile:

Sorry, but… HELP. I can’t find any other solution than ask help to you :expressionless:


I’m always looking for an idea ! :stuck_out_tongue: