您的位置:首页 > 运维架构 > Shell

Mac bash 调用系统对话框

2017-04-23 11:49 162 查看
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')"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: