macos 如何为 Mac OS X 编写启动脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1857838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:35:56  来源:igfitidea点击:

How can I write a startup script for Mac OS X?

macosshellstartup

提问by Sunil Kumar Sahoo

I have created a jar file in java, and I want to make the application automatically start during system boot up. I found I have to write a shell script for that. What should be that shell script look like? Is there anything else I have to do to make an application automatically start at boot up?

我在java中创建了一个jar文件,我想让应用程序在系统启动时自动启动。我发现我必须为此编写一个shell脚本。该 shell 脚本应该是什么样的?我还需要做些什么才能使应用程序在启动时自动启动?

回答by Ned Deily

The preferred way to launch programs at OS X startup is to create a launchddaemon as explained here.

在OS X启动启动程序的首选方法是创建一个launchd作为解释守护在这里

回答by Mobs

In mac os x you can also just run "open program.jar" (or any folder, '-a' for native applications) and it will open detached from the terminal with any default environment settings that it would use if you just double clicked it.

在 mac os x 中,您也可以只运行“open program.jar”(或任何文件夹,对于本机应用程序,'-a'),它将打开与终端分离的任何默认环境设置,如果您双击它会使用它它。

You can also add a program (or the script) to the user's login items through System Preferences > Accounts > 'username' > Login items. This is completely point and click and doesn't require a shell script

您还可以通过“系统偏好设置”>“帐户”>“用户名”>“登录项”将程序(或脚本)添加到用户的登录项中。这完全是点击式操作,不需要 shell 脚本

回答by Vineel Adusumilli

The shellscript would be something like this:

shellscript 应该是这样的:

cd /directory/to/jar
java -jar Jar.jar

Or maybe you don't actually need to write Jar.jar, only Jar. I don't quite remember.

或者也许您实际上不需要编写 Jar.jar,只需要编写 Jar。我不太记得了。