问题描述
我的目标是通过双击OS X .app和用户可以看到的终端来执行Shell脚本(我的脚本具有CLI GUI).
My goal is to execute a shell script by double clicking on an OS X .app, and the Terminal to be visible to the user (my script has a CLI GUI).
有什么想法吗?我已经尝试过应用,但无法显示终端窗口.非常感谢.
Any ideas? I've tried appify but I can't get it to show the Terminal window.Many thanks.
推荐答案
对于那些感兴趣的人,我发现了以下解决方案,其中涉及使用Apple Script命令.
For those interested, I found the following solution which involves using an Apple Script command.
首先,您需要创建launcher.sh脚本.使用下面的代码.下面的许多引号允许您的应用从带有空格的路径运行.
First you need to create a launcher.sh script.Use the code below. The many quotes below allow your app to run from a path with spaces.
#!/bin/bash
scriptPath=$(dirname "$0")'/yourscript.sh'
osascript -e 'tell app "Terminal" to do script "\"'"$scriptPath"'\""'
使用 appify 生成应用程序捆绑包.在终端中键入以下内容:
Use appify to generate an app bundle.Type this in the Terminal to do it:
appify launcher.sh "Your app name"
来自 Finder,右键单击生成的应用程序包,显示包内容,然后将yourscript.sh粘贴到/Contents/MacOS/
From Finder,right-click on your generated app bundle, Show package contents, and paste yourscript.sh into /Contents/MacOS/
这篇关于如何从.app内部执行Shell脚本,并在终端中显示它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!