Mount a server only if the Local address is found.

Hey I am trying to set up a script that will mount a server only if the Local address is actually present. If does not then nothing will happen.

I am using this script to mount:


tell application "Finder"
	try
		mount volume "afp://192.168.0.106/"
	end try
end tell

Thanks for any help.

London

Hi,

actually vanilla AppleScript cannot monitor the available AFP hosts (Apple dropped the ability since Leopard).
I wrote a small command line tool to scan the available hosts with Bonjour. It returns any AFP host including BackToMyMac and Time Capsule hosts

You can download it here: AFPHosts.zip

Thanks for looking into it… I created a script that works for what I need here:


on idle
	try
		do shell script "curl 192.168.0.106/"
		mount volume "afp://192.168.0.106/"
		display dialog "CONNECTED"
		
	on error
		display dialog "NOT CONNECTED"
	end try
	return 0.5 * 60
end idle

However when the server isn’t present it usually returns an error after a min or longer… is there a way to make terminate after say 10 secs.

I was able to resolve the problem myself.

This is my completed script


on idle
	try
		do shell script "curl 192.168.0.106 --connect-timeout 1 -s"
		mount volume "afp://192.168.0.106"
		display dialog "CONNECTED"
		
	on error
		display dialog "NOT CONNECTED"
	end try
	return 0.5 * 60
end idle

Thanks
London