I have a script that prompts a user for input using apple script for their name within my bash script. It seems to work great, but if they do not answer the prompt in about 1 min it prompts again because of a loop I have. Each time it prompts, another window appears on top of the other. So I either need to kill the dialog and I can't figure that out, or have my loop not keep trying every min and I'm not sure how do that either. Below is what my script looks like.
PromptDisplayName ()
{
DISPLAYNAME=$(/usr/bin/osascript << EOF
tell application "System Events"
activate
set DISPLAYNAME to display dialog "Enter Full Name: " default answer "John Doe" with icon note buttons {"OK"} default button 1 with title "Enter Full Name"
return text returned of DISPLAYNAME as string
end tell
EOF
)
Loop until Displayname is in the correct format
until [[ "$DISPLAYNAME" =~ ([a-zA-Z]){3,}[[:blank:]]([a-zA-Z]+){3,} ]]
do
PromptDisplayName
done
}
Call on function to prompt user
PromptDisplayName