简体   繁体   English

如何在OSX中自动启动程序?

[英]How can I make a program start up automatically in OSX?

I have a little program that I want to make open automatically when my mac is started up. 我有一个小程序,我想在我的mac启动时自动打开。

Because this program accepts command line arguments, its not as simple as just going to System Prefs/Accounts/Login items and adding it there... 因为这个程序接受命令行参数,它不仅仅是去系统Prefs / Accounts / Login项目并在那里添加它...

From google, I read that I can create a .profile file in my user's home folder, and that will execute whatever I put in it... So I have a .profile page in ~ like this: 从谷歌,我读到我可以在我的用户的主文件夹中创建.profile文件,这将执行我放入其中的任何内容...所以我有一个.profile页面〜像这样:

-rw-r--r--@ 1 matt staff 27 27 Sep 13:36 .profile -rw-r - r - @ 1 matt staff 27 27 Sep 13:36 .profile

That contains this... 包含这个......

/Applications/mousefix 3.5 / Applications / mousefix 3.5

But it doesn't execute on startup! 但它不会在启动时执行! If I enter "/Applications/mousefix 3.5" manually into the terminal, it does work. 如果我手动输入“/ Applications / mousefix 3.5”到终端,它确实有效。

Any ideas? 有任何想法吗?

From here and into the future, look into launchd for what you want to do. 从这里走向未来,考虑launchd你想要做什么。 All other methods have been deprecated or are now unsupported. 所有其他方法已被弃用或现在不受支持。 This is probably a bit more heavy-weight than what you want, though. 不过,这可能比你想要的更重。

It could also be a problem with your version of the bash shell not correctly executing your .profile . 您的bash shell版本未正确执行.profile也可能是一个问题。 Try putting the command into .bashrc in your home directory, and see if that helps. 尝试将命令放入主目录中的.bashrc ,看看是否有帮助。

您可以使用Lingon来帮助构建launchd的plist文件。

The most general way of launching things on startup on MacOS is using launchd . 在MacOS上启动时启动事物的最常用方法是使用launchd You can create a plist file to tell it to launch your program on startup, which can include arguments. 您可以创建一个plist文件来告诉它在启动时启动您的程序,其中可以包含参数。

您可以使用可运行终端命令的Applescript,然后在启动时启动该AppleScript。

The .profile and .bash_profile only come into play when you open a new shell (ie. opening Terminal or entering through SSH). .profile.bash_profile仅在您打开新shell(即打开终端或通过SSH进入)时发挥作用。 Also, I believe if bash detects .bash_profile it won't look for .profile 另外,我相信如果bash检测到.bash_profile ,它将不会查找.profile
If you want it start upon login, I would look at the other suggestions about launchd 如果你想在登录时开始,我会看看有关launchd的其他建议

您总是可以编写一个包装器脚本,使用您想要的参数运行它

Thanks all. 谢谢大家。 The launchd solution is pretty cool, yes its heavyweight for such a simple thing, but its good to know, and as a developer I'm happy to tinker about :) 推出的解决方案非常酷,是的,对于这么简单的事情,它是重量级的,但它很高兴知道,作为开发人员,我很乐意修补:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM