Mount Network volume else stop


Im trying to create an osascript for use with rsync. I need a script to mount a network volume and if the volume cannot be mounted to stop. I can create the script for mounting the volume, but if it cannot mount the volume it continues for ever. Is there anyway to try for some time and then stops?



Hi Kostas,

welcome to MacScripter :slight_smile:

As the mount volume command displays an alert window with OK button in case of an error,
use the mount_afp shell command. You have to adjust all literal strings except “/bin/ls/Volumes” in the first and second line
If the shared volume is a SMB volume, use the mount_smb command instead, the syntax could be different

if "serverVolume" is not in (do shell script "/bin/ls /Volumes") then
	set flag to mountAFP("user", "pass", "server.local", "serverVolume")
	set flag to true
end if
if flag then
	-- do backup
end if

on mountAFP(user_name, pass_word, thehost, theVolume)
	set theAddress to quoted form of ("afp://" & user_name & ":" & pass_word & "@" & thehost & "/" & theVolume)
	set mountpoint to quoted form of ("/Volumes/" & theVolume)
		do shell script "/bin/mkdir " & mountpoint & "; /sbin/mount_afp " & theAddress & space & mountpoint
		return true
	on error
		do shell script "/bin/rm -r " & mountpoint
		return false
	end try
end mountAFP

Thanks very much for the quick reply. However, if mounting fails, how can I inform the user? With the display dialog command?


yes, display dialog or display alert.

Well stupid of me. Ive added the Display Dialog after the on error.

Ill be back for further instructions:)

No, not inside the handler, there

if flag then
   -- do backup
   display dialog.
end if

FYI: the command for this is mount_smbfs… at least in 10.5

You’re absolutely right. my home is windows free area :wink: