Error checking? Not even sure that's the right term..

Greetings,

I’ll mention up front, I’m AppleScript retarded, and under various constraints that keep me from being able to spend the time to fully learn AS top to bottom. Because of that, I have to beg help off others who know infinitely more then I.

What I need to accomplish now: For various reasons that I won’t go into, I want to use an applescript.app to mount SMB shared folder and open the user’s home folder. I want this to be as idiot proof as possible, because the people that will be using this… well… some of them jsut cannot grasp the concept of computers and computing. So, I’m trying to go with the K.I.S.S. standard.

What I have so far:

tell application "Finder"
	activate
	if exists disk "GROUP_HOME" then
		make new Finder window to folder "username" of disk "GROUP_HOME"
	else
		try
			mount volume "smb://domain;username@foo.org/group_home/"
		end try
		repeat until (list disks) contains "GROUP_HOME"
		end repeat
		make new Finder window to folder "username" of disk "GROUP_HOME"
	end if
end tell

This is all well and good, but now I want to out in some “error checking”, which is probably not the right term. I noticed that if I click “Cancel” button on the SMB authentication window, that it keep coming back over and over, I guess because the AppleScript is trying to do what I’ve told it to do, and I’ve provided no facility for it to fail gracefully. I’m not even sure where to start looking for something like this. Basically I need the script to be able to recognize if someone clicks “Cancel” and have it quit gracefully.

Thanks for any and all help!

OK, someone came up with something that works:

tell application "Finder"
	activate
	if exists disk "GROUP_HOME" then
		make new Finder window to folder "username" of disk "GROUP_HOME"
	else
		try
			mount volume "smb://domain;username@foo.org/GROUP_HOME/"
		on error
			display dialog "Entrprise authentication failed, exiting."
		end try
		repeat until (list disks) contains "GROUP_HOME"
		end repeat
		make new Finder window to folder "username" of disk "GROUP_HOME"
		set current view of Finder window 1 to list view
	end if
end tell

Now the problem is, if a user clicks on “OK” in the error dialog, then the script never ends/quits. If they click on “Cancel” in the error dialog, then it quits fine. Can I completely remove the “OK” button from the dialog box? Or is there something I’m missing to have the error message quit the script gracefully?

Solved it by taking out the “OK” button.

tell application "Finder" 
   activate 
   if exists disk "GROUP_HOME" then 
      make new Finder window to folder "username" of disk "GROUP_HOME" 
   else 
      try 
         mount volume "smb://domain;username@foo.org/GROUP_HOME/" 
      on error 
         display dialog "Enterprise authentication failed, exiting." buttons "Cancel"
      end try 
      repeat until (list disks) contains "GROUP_HOME" 
      end repeat 
      make new Finder window to folder "username" of disk "GROUP_HOME" 
      set current view of Finder window 1 to list view 
   end if 
end tell

Here’s another way to deal with the error dialog. It will terminate the script when the OK button is chosen.

tell application "Finder"
	activate
	if exists disk "GROUP_HOME" then
		make new Finder window to folder "username" of disk "GROUP_HOME"
	else
		try
			mount volume "smb://domain;username@foo.org/GROUP_HOME/"
		on error
			return display dialog "Entrprise authentication failed, exiting." buttons {"OK"} default button 1 with icon 0
		end try
		repeat until (list disks) contains "GROUP_HOME"
		end repeat
		make new Finder window to folder "username" of disk "GROUP_HOME"
		set current view of Finder window 1 to list view
	end if
end tell

– Rob

I added the “delay 1” in the repeat loop because otherwise a loop like that can be a cpu hog. Delay can be less than one, like 0.5, for example.

For what it’s worth, the delay command can be a CPU hog too. In OS X, it has been suggested (by the likes of Apple’s Chris Nebel) to use the shell’s sleep command. This is likely necessary/helpful only with long delays. Unfortunately, as far as I know, it doesn’t handle fractional seconds and, due to the overhead of calling the shell command, a 1 second call might take longer than 1 second. I guess there is always a trade-off.

do shell script “sleep 1”

– Rob (who notes that Tiger’s ‘display dialog’ will have the capability to be secure - I assume this means bulleted input for passwords and such - finally!)

To me though, the more important problem with:

      repeat until (list disks) contains "GROUP_HOME"
                delay 1
      end repeat

is that this script will hang there if the server goes down - the repeat loop will never terminate.

This loop below would stop in 120 seconds:

    repeat with j from 1 to 120
        if (list disks) contains "GROUP_HOME" then
            exit
        else
            delay 1
        end if
    end repeat