【问题标题】:How to execute a shell script from within an .app, and show it in the Terminal?如何从 .app 中执行 shell 脚本,并在终端中显示它?
【发布时间】:2014-10-20 12:02:54
【问题描述】:

我的目标是通过双击 OS X .app 来执行 shell 脚本,并且终端对用户可见(我的脚本有一个 CLI GUI)。

有什么想法吗?我试过appify 但我无法让它显示终端窗口。 非常感谢。

【问题讨论】:

    标签: macos shell


    【解决方案1】:

    对于那些感兴趣的人,我发现了以下涉及使用 Apple Script 命令的解决方案。

    首先您需要创建一个launcher.sh 脚本。 使用下面的代码。下面的许多引号允许您的应用从带有空格的路径运行。

    #!/bin/bash
    scriptPath=$(dirname "$0")'/yourscript.sh'
    osascript -e 'tell app "Terminal" to do script "\"'"$scriptPath"'\""'
    

    使用appify 生成应用程序包。 在终端中输入以下内容:

    appify launcher.sh "Your app name"
    

    从 Finder 中, 右键单击您生成的应用程序包,显示包内容,然后将 yourscript.sh 粘贴到 /Contents/MacOS/

    【讨论】:

    • 做得很好。您可以使用 `open -a Terminal "$scriptPath"` 简化启动器脚本
    猜你喜欢
    • 2017-04-18
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    • 2012-11-18
    • 2019-01-04
    • 2023-04-10
    • 2011-01-11
    相关资源
    最近更新 更多