MAC从shell脚本写入桌面

Den*_*isk 2 macos bash

有没有办法从BASH脚本向MAC桌面显示消息?我正在编写一个终端窗口脚本,需要在MAC桌面上显示一条消息.此外,如果这是一种从BASH脚本打开消息框的方法.

丹尼斯

Mar*_*ell 5

像这样:

#!/bin/bash
osascript -e 'Tell application "System Events" to display dialog "Some Funky Message"'
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

或者,如果您希望用户输入内容并获得结果...

#!/bin/bash
input=$(osascript -e 'Tell application "System Events" to display dialog "Enter something:" default answer ""' -e 'text returned of result' 2>/dev/null)
echo $input
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

并且,为了预测您的下一个问题,如果您想要bash对话框中的变量以及引号和内容,您可以使用以下形式将脚本发送到osascript其上stdin:

#!/bin/bash
var=7
input=$(osascript <<EOF
Tell application "System Events" to display dialog "Steve's Funky Message ($var) with apostrophe and variable"
EOF)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述