1

我有一堆 shell 脚本和可执行文件,我想将它们打包到一个独立的 Mac .app 包中。我还需要向用户显示一个输入对话框,以便我可以获取一个值并将其用作我的一个 shell 脚本的输入。

我注意到Automator允许您创建一个独立的应用程序并向工作流添加输入对话框,但我不清楚如何:

  • 在 .app 包中包含我的可执行文件
  • 在添加“运行 shell 脚本”操作时指定相对路径,这样当用户双击 .app 时我可以执行我的可执行文件

另一方面,我找到了 appify,它解释了如何将单个 bash 脚本转换为可点击的 .app。很好,但我仍然需要输入对话框位。

我必须使用哪些替代方法来创建具有上述要求的 .app 文件?

4

1 回答 1

0

您可以应用程序将其包装在 .app 包中,并让脚本本身通过 AppleScript 使用以下osascript命令显示输入对话框:

ans="$(osascript -e 'Tell application "System Events" to activate' \
    -e 'Tell application "System Events" to display dialog "What?" default answer "Fugeddaboutit" buttons {"Yup", "Nope", "Cancel"} default button 1' \
    -e '(button returned of result) & ":" & (text returned of result)' 2>/dev/null)"

if [[ $? -ne 0 ]]; then
    echo "You cancelled!"
else
    echo "You entered '${ans#*:}', and pushed the ${ans%%:*} button."
fi
于 2011-09-01T21:42:20.317 回答