Simple display dialog with more options

Sometimes we need something more and simple display dialog.

  • We could force the user for input string.
  • We could also define what kind of delimiters we want for the input string. (useful in unix world)
(**
* Display dialog with title and default answer.
* 		Force the user to input text, also include delimeter for returned text. 
*)
my dialogWithTitle:"Input reference: " default:"" delimiter:"_"
on dialogWithTitle:theTitle default:theDefault delimiter:theDelimiter
	set status to false
	repeat while status is false
		set result to (display dialog theTitle default answer theDefault)'s text returned
		if result is not "" then set {dialogString, status} to {result, true}
	end repeat
	if dialogString contains space then
		set ASTID to AppleScript's text item delimiters
		set AppleScript's text item delimiters to space
		set dialogString to every text item of dialogString
		set AppleScript's text item delimiters to theDelimiter
		set dialogString to dialogString as text
		set AppleScript's text item delimiters to ASTID
	end if
	return dialogString
end dialogWithTitle:default:delimiter: