auto-connect server

I want to automatically connect to my server whenever i plug into the network. I have so far come up with this script



set the_interface to 0
repeat
	set ip_internal to ""
	try
		set ip_internal to do shell script ("ipconfig getifaddr en" & the_interface)
	end try
	if ip_internal is not "" then
		try
			mount volume "afp://192.168.1.3/shared"
			
		end try
	else
		try
			return no
		end try
	end if
end repeat

I have two problems
Whenever i run this with no ethernet cable plugged in, it exits immediatly, but when i run it with the cable conencted, it hangs, and does not exit. How do i make it exit as soon as it mounts the volume.

Also, is there anyway of launching this at startup, and get it to check every five minutes to see if the ethernet cable is plugged in.

Thanks

Gary

Model: MacBook
Browser: Firefox 3.0.7
Operating System: Mac OS X (10.5)

Moved from Code Exchange to AppleScript | OS X. Code Exchange is for finished, working scripts to be shared with the community. AppleScript | OS X is for questions.

Hi,

try Bonjour Mounter

Bonjour Mounter that StefanK linked looks to do exactly what you want, but if you want a bit more flexibility or do other tasks, you can try MarcoPolo.