Basic question after a dialog

Hello,

For this script:

set myBackupDiskName to "BC-CESU"
set myContinue to "Yes"

tell application "Finder" to if name of every disk does not contain myBackupDiskName then
	try	
		mount volume "smb://HOBSON Andrew:nike4@10.192.120.25/" & myBackupDiskName
	on error e number n		
		set myContinue to "No"
		display dialog "Erreur: " & e buttons {"Annuler"} default button 1
		display dialog "Number: " & n buttons {"Annuler"} default button 1	end try
end if

if myContinue is "Yes" then
	set SourceFolder to "MacOS 10.3.9:User Guides and Information:"
	set DestFolder to "BC-CESU:5 Management Logistique:5.1 Informatique:Backups:"
	
	tell application "Finder"
		duplicate every file of folder SourceFolder to folder DestFolder with replacing
	end tell
end if

If I get in the section “on error e number n”, the script ends its execution after the first dialog dispaying the error text. Why doesn’t it continue after to display the second dialog?

Thanks for the help.

Andrew Hobson

Hi Andrew,

because the Cancel (or localized Annuler) button creates an error -128 (user canceled),
which aborts the script, if it’s not within a try block

Here you go, this should work:


set myBackupDiskName to "BC-CESU"
set myContinue to "Yes"

tell application "Finder" to if name of every disk does not contain myBackupDiskName then
	try
		mount volume "smb://HOBSON Andrew:nike4@10.192.120.25/" & myBackupDiskName
	on error e number n
		set myContinue to "No"
		the button returned of (display dialog "Erreur: " & e buttons {" Annuler "} default button 1)
		display dialog "Number: " & n buttons {" Annuler "} default button 1
	end try
end if

if myContinue is "Yes" then
	set SourceFolder to "MacOS 10.3.9:User Guides and Information:"
	set DestFolder to "BC-CESU:5 Management Logistique:5.1 Informatique:Backups:"
	
	tell application "Finder"
		duplicate every file of folder SourceFolder to folder DestFolder with replacing
	end tell
end if