Mount Volume Troubles


the following script works and is a subset of more complex script:

set pathVolume to “myServerPath”
set nomeVolume to “myVolumePath”
mount volume (“afp://” & pathVolume & “/” & nomeVolume) as user name “myUser” with password “myPwd”
on error msg number errnum
display dialog “My Error”
end try

but if for any reason the server or the network is down, an error that is NOT captured by the try on error is generated. After user press manually “OK” the display dialog “My Error” appear.

How to prevent the dialog error generated by operating system?
The script should work on machine that mount a lot of volumes.
I can check also if the volume is present in the list disks but if network goes down and after the 600 seconds timeout (10 minutes) the volume are automatically unmounted by OS X and if network is again down or server is down the script generate the above dialog.


On my machine which is not connected to a network,

mount volume “afp://truc”

issue an error number -5000

When the machine is connected to a network, it’s supposed to return “a specifier for the mounted volume”

I guess that when the volume is unavailable, it returns an empty string or missing value.

KOENIG Yvan (VALLAURIS, France) jeudi 27 juin 2013 10:47:14

Hi Yvan,

If you try this, supposing that server is network is up and server is down:

set a to mount volume “afp://truc”
on error msg number errnum
display dialog errnum
end try

Before the -5000 error you get an OS X dialog that say:

There was a problem connecting to the server “truc”.
The server may not exist or it is unavailable at this time.

And the dialog remain on screen… How to solve that?



as far as I know the only way to avoid the error message is to create the mount point explicitly with mkdir
and mount the volume with mount_afp

property server : "myServer.local"
property serverVolume : "Server"
property user : "user"
property pass : "pass"

set isMounted to serverVolume is in (do shell script "/bin/ls /Volumes") or mountAFP(user, pass, server, serverVolume)

if isMounted then
	-- do something
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 e
		log e
		do shell script "/bin/rm -r " & mountpoint
		return false
	end try
end mountAFP


I post here a possible solution:

property serverList : missing value
property logPath : “Mountain Lion:Users:adminosx:Desktop:mountServerLog.txt”

set serverList to {}
copy {“myVolume_1”, “myServerAddress_1”} to end of serverList
copy {“myVolume_2”, “myServerAddress_2”} to end of serverList
copy {“myVolume_3”, “myServerAddress_3”} to end of serverList – any server can be simply commented so the serverList array will not contains it

on idle
repeat with j from 1 to count serverList
set volumeName to item 1 of item j of serverList
set serverAddress to item 2 of item j of serverList

		do shell script "ping -c 2 " & serverAddress
		set serverIsAvailable to true
	on error msg number errnum
		set serverIsAvailable to false
		set timeString to do shell script "/bin/date '+%d %b %Y %H:%M:%S'"
		set fileRef to open for access file logPath with write permission
		write (timeString & tab & serverAddress & tab & "NOT AVAILABLE" & return) to fileRef starting at eof
		close access fileRef
	end try
	if serverIsAvailable is true then
			if volumeName is not in (list disks) then
				mount volume ("afp://" & serverAddress & "/" & volumeName) as user name "myUser" with password "myPassword"
			end if
		on error msg number errnum
			display dialog "Error:" & msg giving up after 60
		end try
	end if
end repeat
return 120

end idle

on quit
continue quit
end quit

I tested also removing Ethenet cable. A dialog that list all server will be dismissed after 600 seconds taht is timeout of OS X related to afp.
The same dialog is dismissed when you reconnect the Ethernet cable.
The dialog emntioned in previou post never appear because now there is a “ping” controlling that prevent the modal dialog that can’t be dismissed.
Also I added a log to verify when a particular server was not reachable.
I will move in production… :slight_smile:


Stefan’s solution is indeed one way to suppress error messages. However I prefer an extra check if the node is an directory or really mounted. I posted it a few years ago here