dialog with actions

Hi guys I have this script that works great

set Alias1 to choose folder
set theName to text returned of (display dialog "Job Name" default answer "Example: Jane_Doe_12_03_07")
set theNumber to text returned of (display dialog "number of shot folders" default answer "Example: 10")
tell application "Finder"
	set dir_1 to make new folder at Alias1 with properties {name:theName}
	set dir_2 to make new folder at dir_1 with properties {name:"Processed"}
	set dir_3 to make new folder at dir_1 with properties {name:"Trash"}
	set dir_4 to make new folder at dir_1 with properties {name:"Captures"}
	repeat with i from 1 to theNumber
		make new folder at dir_4 with properties {name:(theName & "_shot_" & (text -3 through -1 of ("00" & i)))}
	end repeat
	repeat with i from 1 to theNumber
		make new folder at dir_2 with properties {name:(theName & "_shot_" & (text -3 through -1 of ("00" & i) & "_processed"))}
	end repeat
end tell

But now want to add a dialog box that either runs the second repeat or not. I have tried

set Alias1 to choose folder
set theName to text returned of (display dialog "Job Name" default answer "Example: Jane_Doe_12_03_07")
set theNumber to text returned of (display dialog "number of shot folders" default answer "Example: 10")
tell application "Finder"
	set dir_1 to make new folder at Alias1 with properties {name:theName}
	set dir_2 to make new folder at dir_1 with properties {name:"Processed"}
	set dir_3 to make new folder at dir_1 with properties {name:"Trash"}
	set dir_4 to make new folder at dir_1 with properties {name:"Captures"}
	display dialog "do you want seperate process folder" buttons {"YES", "NO"} default button 2
	repeat with i from 1 to theNumber
		make new folder at dir_4 with properties {name:(theName & "_shot_" & (text -3 through -1 of ("00" & i)))}
	end repeat
	if the button returned of the result is "YES" then
		repeat with i from 1 to theNumber
			make new folder at dir_2 with properties {name:(theName & "_shot_" & (text -3 through -1 of ("00" & i) & "_processed"))}
		end repeat
	else
		set Alias1 to front window
	end if
end tell

But I get get an error saying that it cant get the result of the dialog.
Any help would be great.

Hi,

result contains always the result of the last line,
in your case the reference to the most recent created folder.
Using a variable solves the problem


set Alias1 to choose folder
set theName to text returned of (display dialog "Job Name" default answer "Example: Jane_Doe_12_03_07")
set theNumber to text returned of (display dialog "number of shot folders" default answer "Example: 10")
tell application "Finder"
	set dir_1 to make new folder at Alias1 with properties {name:theName}
	set dir_2 to make new folder at dir_1 with properties {name:"Processed"}
	set dir_3 to make new folder at dir_1 with properties {name:"Trash"}
	set dir_4 to make new folder at dir_1 with properties {name:"Captures"}
	set theResult to button returned of (display dialog "do you want seperate process folder" buttons {"YES", "NO"} default button 2)
	repeat with i from 1 to theNumber
		make new folder at dir_4 with properties {name:(theName & "_shot_" & (text -3 through -1 of ("00" & i)))}
	end repeat
	if theResult is "YES" then
		repeat with i from 1 to theNumber
			make new folder at dir_2 with properties {name:(theName & "_shot_" & (text -3 through -1 of ("00" & i) & "_processed"))}
		end repeat
	else
		set Alias1 to front window
	end if
end tell