欢迎各位兄弟 发布技术文章
这里的技术是共享的
要在 osascript
的 display dialog
命令中添加标题,可以使用 with title
参数。以下是带有标题的完整命令:
bash/usr/bin/osascript -e 'display dialog "已创建索引!" buttons {"OK"} default button "OK" with title "提示"'
"已创建索引!"
是对话框的正文内容
buttons {"OK"}
指定对话框按钮(这里只有一个"OK"按钮)
default button "OK"
设置默认按钮
with title "提示"
添加对话框标题(将"提示"替换为你想要的标题文字)
多按钮示例:
bashosascript -e 'display dialog "操作已完成" buttons {"取消", "确定"} default button "确定" with title "系统通知"'
获取用户选择:
bashresult=$(osascript -e 'display dialog "要继续吗?" buttons {"否", "是"} default button "是" with title "确认"') echo "用户选择了: $result"
带图标警告:
bashosascript -e 'display dialog "数据保存失败!" with icon stop buttons {"OK"} with title "错误"'
注意:在macOS中,对话框标题会显示在窗口顶部,而正文内容会以较大字体显示在对话框中央。