如何让 OSX 中的程序自动启动?

发布于 2024-07-07 02:31:36 字数 390 浏览 10 评论 0原文

我有一个小程序,我想在我的 mac 启动时自动打开它。

因为这个程序接受命令行参数,所以它不像只是进入系统首选项/帐户/登录项并将其添加到那里那么简单...

从谷歌,我读到我可以在用户的​​主文件夹中创建一个 .profile 文件,并且它将执行我放入其中的任何内容...所以我在 ~ 中有一个 .profile 页面,如下所示:

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

其中包含此...

/Applications/mousefix 3.5

但它不会在启动时执行! 如果我在终端中手动输入“/Applications/mousefix 3.5”,它就会起作用。

有任何想法吗?

I have a little program that I want to make open automatically when my mac is started up.

Because this program accepts command line arguments, its not as simple as just going to System Prefs/Accounts/Login items and adding it there...

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:

-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.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

善良天后 2024-07-14 02:31:36

从现在开始,展望未来,请深入了解 lau nchd 为您服务想做。 所有其他方法已被弃用或现在不受支持。 不过,这可能比您想要的要重一些。

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

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.

可遇━不可求 2024-07-14 02:31:36

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

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

半寸时光 2024-07-14 02:31:36

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

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.

稀香 2024-07-14 02:31:36

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

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

北座城市 2024-07-14 02:31:36

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

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

南薇 2024-07-14 02:31:36

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

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

热血少△年 2024-07-14 02:31:36

谢谢大家。 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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文