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

时间:2021-12-02 00:23:17

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

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?

7 个解决方案

#1


11  

From here and into the future, look into launchd for what you want to do. 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. Try putting the command into .bashrc in your home directory, and see if that helps.

您的版本的bash shell无法正确执行.profile也可能是一个问题。尝试将命令放入主目录中的.bashrc,看看是否有帮助。

#2


4  

You can use Lingon to help construct a plist file for launchd.

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

#3


3  

The most general way of launching things on startup on MacOS is using launchd. You can create a plist file to tell it to launch your program on startup, which can include arguments.

在MacOS上启动时启动事物的最常用方法是使用launchd。您可以创建一个plist文件来告诉它在启动时启动您的程序,其中可以包含参数。

#4


1  

You can use Applescript which can run terminal commands, then have that applescript launched at startup.

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

#5


1  

The .profile and .bash_profile only come into play when you open a new shell (ie. opening Terminal or entering through SSH). Also, I believe if bash detects .bash_profile it won't look for .profile
If you want it start upon login, I would look at the other suggestions about launchd

.profile和.bash_profile仅在您打开新shell(即打开终端或通过SSH进入)时发挥作用。此外,我相信如果bash检测到.bash_profile它将不会查找.profile如果你想在登录时启动它,我会看看有关launchd的其他建议

#6


0  

You could always write a wrapper script that runs it with the arguments you want

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

#7


0  

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 :)

谢谢大家。推出的解决方案非常酷,是的,对于这么简单的事情,它的重量级,但它的好消息,作为一个开发人员,我很高兴修补:)

#1


11  

From here and into the future, look into launchd for what you want to do. 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. Try putting the command into .bashrc in your home directory, and see if that helps.

您的版本的bash shell无法正确执行.profile也可能是一个问题。尝试将命令放入主目录中的.bashrc,看看是否有帮助。

#2


4  

You can use Lingon to help construct a plist file for launchd.

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

#3


3  

The most general way of launching things on startup on MacOS is using launchd. You can create a plist file to tell it to launch your program on startup, which can include arguments.

在MacOS上启动时启动事物的最常用方法是使用launchd。您可以创建一个plist文件来告诉它在启动时启动您的程序,其中可以包含参数。

#4


1  

You can use Applescript which can run terminal commands, then have that applescript launched at startup.

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

#5


1  

The .profile and .bash_profile only come into play when you open a new shell (ie. opening Terminal or entering through SSH). Also, I believe if bash detects .bash_profile it won't look for .profile
If you want it start upon login, I would look at the other suggestions about launchd

.profile和.bash_profile仅在您打开新shell(即打开终端或通过SSH进入)时发挥作用。此外,我相信如果bash检测到.bash_profile它将不会查找.profile如果你想在登录时启动它,我会看看有关launchd的其他建议

#6


0  

You could always write a wrapper script that runs it with the arguments you want

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

#7


0  

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 :)

谢谢大家。推出的解决方案非常酷,是的,对于这么简单的事情,它的重量级,但它的好消息,作为一个开发人员,我很高兴修补:)