Wait until server mounts before trying to copy file.

I need to add something to my script that mounts a server and copies a file that waits until the server is mounted before it tries to copy. I have tried putting in a set delay but sometimes it just takes a little longer to mount the server. I thought maybe this would work but I guess I was wrong.

repeat
if (list disks) does not contain iVolume then exit repeat
end repeat

Having AppleScript go crazy with a repeat loop to poll for information is a bit of a performance sniper. You’ve got a couple of choices:

  1. A modification of what you tried to do. Repeat, poll to see if the server was mounted successfully, but then wait some amount of time before beginning the repeat again if you don’t get one of the results you want to catch. You wouldn’t want this delay to be too long OR short, so you’d want to experiment to find something that didn’t delay you too much during repeats and also didn’t burn CPU cycles repeating too quickly.

repeat
if (a check to see if your server is mounted) then
-- copy some files or whatever
exit repeat
end if

delay 5
end repeat

  1. Use a shell script to mount the server. AppleScript will block until the exit signal comes back from the shell. You can use the exit signal to determine if the server got mounted successfully, and then proceed with your file operations.

if i do it via a shell script, what is the best way to mount it. I have to pass along the user name and password. the user name i guess could be done by doing a whoami the password i am having the person enter via the apple script how can i pass that alog to the shell script?

Assuming afp this would be the way to mount via the shell

tell application "System Events"
	set UserName to name of current user
end tell
display dialog "Please enter your password" default answer ""
set pWord to text returned of result
do shell script "/bin/mkdir /Volumes/sharename; /sbin/mount -t afp afp://" & UserName & ":" & pWord & "@rhost/sharename /Volumes/sharename"