Show error message:
#!/usr/bin/env bash
# error "Message"
function error() {
osascript <<EOT
tell app "System Events"
display dialog "$1" buttons {"OK"} default button 1 with icon caution with title "$(basename $0)"
return -- Suppress result
end tell
EOT
}
error "Not enough cheese!"
(You can use note
or stop
instead of caution
to show a different icon.)
Ask question:
#!/usr/bin/env bash
# prompt "Question" "Default value"
function prompt() {
osascript <<EOT
tell app "System Events"
text returned of (display dialog "$1" default answer "$2" buttons {"OK"} default button 1 with title "$(basename $0)")
end tell
EOT
}
value="$(prompt 'Enter:' '42')"