#!/usr/bin/env bash
if ! username=$(osascript 2> /dev/null <<-EOF
tell application "System Events"
activate
return text returned of (display dialog "Enter your name" with title ¬
"Question" default answer "" buttons {"Cancel", "Rename"} default button "Rename")
end tell
EOF
); then
exit 1
fi
# Continue to do something with $username...
echo "$username"