Dialog Maker

This will halve the time it takes to make those tedious dialogs, it includes all the features of display dialog (maybe some you didn’t know) but you can take some out if you like.

set valtext to text returned of (display dialog "Please type the text for your dialog." default answer "" with title "Dialog Text")
if button returned of (display dialog "Would you like your dialog to have a text entry?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Text Entry") is "Yes" then
	set valent to " default answer \""
	set valentdef to text returned of (display dialog "If you would like to, please now type the default text for your text entry." default answer "" with title "Default Answer")
	if button returned of (display dialog "Would you like the text entry to be secure?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Secure Text Entry") is "Yes" then
		set valentsec to "\" with hidden answer"
	else
		set valentsec to "\""
	end if
else
	set valent to ""
	set valentdef to ""
	set valentsec to ""
end if

if button returned of (display dialog "Would you like to use custom buttons?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Custom Buttons") is "Yes" then
	display dialog "Please enter the label of the first button.
Click Done to have just one button or click Next Button to label the second/third" default answer "Cancel" buttons {"Cancel", "Done", "Next Button"} default button 3 with title "1st Button"
	set {valbut1, valbut1b} to {text returned of result, button returned of result}
	set valbut to " buttons {\"" & valbut1 & "\"}"
	set valbutlist to "1"
	if valbut1b is "Next Button" then
		display dialog "Please enter the label of the second button.
Click Done to have just one button or click Next Button to label the third." default answer "" buttons {"Cancel", "Done", "Next Button"} default button 2 with title "2nd Button"
		set {valbut2, valbut2b} to {text returned of result, button returned of result}
		set valbut to " buttons {\"" & valbut1 & "\",\"" & valbut2 & "\"}"
		set valbutlist to {valbut1, valbut2}
		if valbut2b is "Next Button" then
			set valbut3 to the text returned of (display dialog "Please enter the label of the third button." default answer "" buttons {"Cancel", "Done"} default button 2 with title "3rd Button")
			set valbut to " buttons {\"" & valbut1 & "\",\"" & valbut2 & "\",\"" & valbut3 & "\"}"
			set valbutlist to {valbut1, valbut2, valbut3}
		end if
	end if
	set valdia to "Would you like to set a default button?"
	set valdiadef to 2
else
	set valdiadef to 3
	set valbut to ""
	set valdia to "Would you like to change the default button?"
	set valbutlist to {"Cancel", "OK"}
end if

if button returned of (display dialog valdia buttons {"Cancel", "Yes", "No"} default button valdiadef with title "Default Button") is "Yes" then
	if valbutlist is "1" then
		set valbutdef to " default button \"" & valbut1 & "\""
	else
		set valbutdef to " default button \"" & (choose from list valbutlist with prompt "Please choose a button to be the default:" with title "Choose Default Button") & "\""
	end if
else
	set valbutdef to ""
end if

if valbutlist contains "Cancel" then
	set valcandia to "Would you like to change the Cancel button?"
else
	set valcandia to "Would you like to set a Cancel button?"
end if
if button returned of (display dialog valcandia buttons {"Cancel", "Yes", "No"} default button 3 with title "Cancel Button") is "Yes" then
	set valbutcal to " cancel button \"" & (choose from list valbutlist with prompt "Please choose a button to be the canceller:" with title "Choose Cancel Button") & "\""
else
	set valbutcal to ""
end if

if button returned of (display dialog "Would you like to add a title?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Title") is "Yes" then
	display dialog "Please enter your window title and click Done or click Use Script Name to set the window title to the name of your script." default answer "" buttons {"Cancel", "Use Script Name", "Done"} default button "Done" with title "Choose Title"
	set {valtitdiabut, valtitdiatxt} to {button returned of result, text returned of result}
	if valtitdiabut is "Done" then
		set valtit to " with title \"" & valtitdiatxt & "\""
	else
		set valscptname to (get the name of the front window of application "AppleScript Editor")
		set valtit to " with title \"" & valscptname & "\""
	end if
else
	set valtit to ""
end if

if button returned of (display dialog "Would you like to add an icon?" buttons {"Cancel", "Yes", "No"} default button "No" with title "Icon") is "Yes" then
	if button returned of (display dialog "Would you like to select your own icon file or use one of the presets?" buttons {"Cancel", "Choose File", "Choose Preset Icon"} default button "Choose Preset Icon" with title "Icon") is "Choose Preset Icon" then
		set valicon to " with icon " & (choose from list {"note", "caution", "stop"} with prompt "Please choose an icon:" with title "Choose Icon")
	else
		set valicon to " with icon alias \"" & (choose file of type {"com.apple.icns"} with prompt "Please choose a .icns file:") & "\""
	end if
else
	set valicon to ""
end if

if button returned of (display dialog "Would you like a timeout?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Timeout") is "Yes" then
	
	set valtmouttst to text returned of (display dialog "Please enter your timeout period in seconds:" default answer "" buttons {"Cancel", "Done"} default button "Done" with title "Choose Timeout")
	try
		valtmouttst as number
		if valtmouttst is "0" then
			error
		end if
		if valtmouttst is "" then
			error
		end if
		set valtmout to " giving up after " & valtmouttst
	on error error_message
		repeat
			set valtmouttst to text returned of (display dialog "Please enter an integer more than 0 (decimals will be rounded down):" default answer "" buttons {"Cancel", "Done"} default button "Done" with title "Choose Timeout")
			try
				valtmouttst as number
				if valtmouttst is "0" then
					error
				end if
				if valtmouttst is "" then
					error
				end if
				set valtmout to " giving up after " & valtmouttst
				exit repeat
			end try
		end repeat
	end try
else
	set valtmout to ""
end if

tell application "AppleScript Editor"
	activate
	tell application "System Events"
		keystroke "display dialog \"" & valtext & "\"" & valent & valentdef & valentsec & valbut & valbutdef & valbutcal & valtit & valicon & valtmout
	end tell
end tell

I made a tweak a little bit. I learned SO much from this script about dialogs. Here’s the script:


set valtext to text returned of (display dialog "Please type the text for your dialog." default answer "" with title "Dialog Text")
if button returned of (display dialog "Would you like your dialog to have a text entry?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Text Entry") is "Yes" then
	set valent to " default answer \""
	set valentdef to text returned of (display dialog "If you would like to, please now type the default text for your text entry." default answer "" with title "Default Answer")
	if button returned of (display dialog "Would you like the text entry to be secure?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Secure Text Entry") is "Yes" then
		set valentsec to "\" with hidden answer"
	else
		set valentsec to "\""
	end if
else
	set valent to ""
	set valentdef to ""
	set valentsec to ""
end if

if button returned of (display dialog "Would you like to use custom buttons?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Custom Buttons") is "Yes" then
	display dialog "Please enter the label of the first button.\nClick Done to have just one button or click Next Button to label the second/third" default answer "Cancel" buttons {"Cancel", "Done", "Next Button"} default button 3 with title "1st Button"
	set {valbut1, valbut1b} to {text returned of result, button returned of result}
	set valbut to " buttons {\"" & valbut1 & "\"}"
	set valbutlist to "1"
	if valbut1b is "Next Button" then
		display dialog "Please enter the label of the second button.\nClick Done to have just one button or click Next Button to label the third." default answer "" buttons {"Cancel", "Done", "Next Button"} default button 2 with title "2nd Button"
		set {valbut2, valbut2b} to {text returned of result, button returned of result}
		set valbut to " buttons {\"" & valbut1 & "\",\"" & valbut2 & "\"}"
		set valbutlist to {valbut1, valbut2}
		if valbut2b is "Next Button" then
			set valbut3 to the text returned of (display dialog "Please enter the label of the third button." default answer "" buttons {"Cancel", "Done"} default button 2 with title "3rd Button")
			set valbut to " buttons {\"" & valbut1 & "\",\"" & valbut2 & "\",\"" & valbut3 & "\"}"
			set valbutlist to {valbut1, valbut2, valbut3}
		end if
	end if
	set valdia to "Would you like to set a default button?"
	set valdiadef to 2
else
	set valdiadef to 3
	set valbut to ""
	set valdia to "Would you like to change the default button?"
	set valbutlist to {"Cancel", "OK"}
end if

if button returned of (display dialog valdia buttons {"Cancel", "Yes", "No"} default button valdiadef with title "Default Button") is "Yes" then
	if valbutlist is "1" then
		set valbutdef to " default button \"" & valbut1 & "\""
	else
		set valbutdef to " default button \"" & (choose from list valbutlist with prompt "Please choose a button to be the default:" with title "Choose Default Button") & "\""
	end if
else
	set valbutdef to ""
end if

if valbutlist contains "Cancel" then
	set valcandia to "Would you like to change the Cancel button?"
else
	set valcandia to "Would you like to set a Cancel button?"
end if
if button returned of (display dialog valcandia buttons {"Cancel", "Yes", "No"} default button 3 with title "Cancel Button") is "Yes" then
	set valbutcal to " cancel button \"" & (choose from list valbutlist with prompt "Please choose a button to be the canceller:" with title "Choose Cancel Button") & "\""
else
	set valbutcal to ""
end if

if button returned of (display dialog "Would you like to add a title?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Title") is "Yes" then
	display dialog "Please enter your window title and click Done or click Use Script Name to set the window title to the name of your script." default answer "" buttons {"Cancel", "Use Script Name", "Done"} default button "Done" with title "Choose Title"
	set {valtitdiabut, valtitdiatxt} to {button returned of result, text returned of result}
	if valtitdiabut is "Done" then
		set valtit to " with title \"" & valtitdiatxt & "\""
	else
		set valscptname to (get the name of the front window of application "AppleScript Editor")
		set valtit to " with title \"" & valscptname & "\""
	end if
else
	set valtit to ""
end if

if button returned of (display dialog "Would you like to add an icon?" buttons {"Cancel", "Yes", "No"} default button "No" with title "Icon") is "Yes" then
	if button returned of (display dialog "Would you like to select your own icon file or use one of the presets?" buttons {"Cancel", "Choose File", "Choose Preset Icon"} default button "Choose Preset Icon" with title "Icon") is "Choose Preset Icon" then
		set valicon to " with icon " & (choose from list {"note", "caution", "stop"} with prompt "Please choose an icon:" with title "Choose Icon")
	else
		set valicon to " with icon alias \"" & (choose file of type {"com.apple.icns"} with prompt "Please choose a .icns file:") & "\""
	end if
else
	set valicon to ""
end if

if button returned of (display dialog "Would you like a timeout?" buttons {"Cancel", "Yes", "No"} default button 3 with title "Timeout") is "Yes" then
	
	set valtmouttst to text returned of (display dialog "Please enter your timeout period in seconds:" default answer "" buttons {"Cancel", "Done"} default button "Done" with title "Choose Timeout")
	try
		valtmouttst as number
		if valtmouttst is "0" then
			error
		end if
		if valtmouttst is "" then
			error
		end if
		set valtmout to " giving up after " & valtmouttst
	on error error_message
		repeat
			set valtmouttst to text returned of (display dialog "Please enter an integer more than 0 (decimals will be rounded down):" default answer "" buttons {"Cancel", "Done"} default button "Done" with title "Choose Timeout")
			try
				valtmouttst as number
				if valtmouttst is "0" then
					error
				end if
				if valtmouttst is "" then
					error
				end if
				set valtmout to " giving up after " & valtmouttst
				exit repeat
			end try
		end repeat
	end try
else
	set valtmout to ""
end if

tell application "AppleScript Editor"
	activate
	make new document
	set text of front document to "display dialog \"" & valtext & "\"" & valent & valentdef & valentsec & valbut & valbutdef & valbutcal & valtit & valicon & valtmout
compile front document
end tell

Model: Aluminum Macbook
AppleScript: 2.1
Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Sorry would you point out exactly what you did please, veeeerrryyy large!

Actually I see the end bit, not sure why you would want a new script for each dialog but OK. Did you do anything else?

Used it much? Did it speed it up? Make it easier?

I’m trying to make an ASOC version like Craig suggested to me, if I work out this weird ObjC stuff it will be good.

All it did was at the end. Open it in an applescript editor. Thats it. No much really.