1

我想在我的脚本在后台运行时创建一个启动屏幕/活动对话框,以通知用户正在发生的事情。我的脚本文件启动了本地应用程序的不同组件,并且有一堆用户不需要看到/不会理解的单词和内容。我知道如何让脚本在后台运行,但我想知道如何在每个组件启动后显示一个对话框、新的终端窗口、通知或类似的东西让用户知道。

例如,我有 4 个组件,所以框会出现并说:

第 4 部分中的第 1 部分已成功启动..

第 4 部分中的第 2 部分已成功启动..

等等...

任何帮助表示赞赏,因为我已经搜索了一段时间没有运气。要添加的一件事是,我能够使用以下代码打开一个新的终端窗口:/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal &

这很好,但是当我回显时,它仍然会转到第一个。

4

1 回答 1

0

您还可以通过启动通知消息来通知用户:

osascript -e 'display notification "hello"'

甚至是一个对话框,但这会等待用户单击“确定”按钮:

osascript -e 'display alert "Hello"'

例子:

#!/bin/bash

osascript -e 'display notification "Component 1 of 4 successfully started.." with title "in progress"'
sleep 2
osascript -e 'display notification "Component 2 of 4 successfully started.." with title "in progress"'
sleep 2
osascript -e 'display alert "Processing done."'
于 2018-12-18T03:02:15.857 回答