-->

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

2020-07-14 15:22发布

问题:

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?

回答1:

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



回答2:

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.

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



回答3:

The shellscript would be something like this:

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.