MAC从Shell脚本写入桌面 [英] MAC write to desktop from shell script

查看:62
本文介绍了MAC从Shell脚本写入桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以从BASH脚本向MAC桌面显示消息?我正在编写一个终端窗口脚本,该脚本需要在MAC桌面上显示一条消息.同样,如果这是从BASH脚本中打开消息框的一种方式.

Is there a way to display messages to the MAC desktop from a BASH script? I am writing a terminal window script, that needs to display a message on the MAC desktop. Also if the was a way to open a message box from a BASH script.

丹尼斯

推荐答案

像这样:

#!/bin/bash
osascript -e 'Tell application "System Events" to display dialog "Some Funky Message"'

或者,如果您希望用户输入一些东西并获得结果...

Or, if you want the user to input something and get the result...

#!/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

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

And, to anticipate your next question, if you want bash variables in the dialog box and also quotes and stuff, you can use this form of sending the script into osascript on its 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)

这篇关于MAC从Shell脚本写入桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆