如何让我的菜单栏应用程序在登录时启动?

时间:2022-05-30 07:47:53

I have made an app which shows your IP address in the menu bar. It has no dock icon and only runs in the menu bar.

我制作了一个应用程序,在菜单栏中显示您的IP地址。它没有停靠图标,只能在菜单栏中运行。

I want this app to launch at login. I made a script which uses osascript to add the name.app to the login items, however I wan't to deploy this app and this isn't a proper solution.

我希望这个应用程序在登录时启动。我创建了一个脚本,使用osascript将name.app添加到登录项,但是我不想部署这个应用程序,这不是一个合适的解决方案。

I have tried following guides on creating a launchd launch agent/dameon however none of them show me how to get my app created in Xcode to create and copy a plist into ~/Library/LaunchAgents. I can make it manually, put it in place and it works, but how do I get a user (who just drags my app from a .dmg into the applications folder) to copy a launch agent too?

我曾尝试过关于创建launchd启动代理/ dameon的指南,但是没有一个向我展示如何在Xcode中创建我的应用程序以创建并将plist复制到〜/ Library / LaunchAgents。我可以手动制作它,把它放到位并且它可以工作,但是我如何让用户(只是将我的应用程序从.dmg拖到应用程序文件夹中)来复制启动代理?

1 个解决方案

#1


1  

Probably the best way of doing this now is to bundle the LoginItem inside the app bundle's Contents directory. You can then use SMLoginItemSetEnabled() to enable it.

现在最好的方法是将LoginItem捆绑在app bundle的Contents目录中。然后,您可以使用SMLoginItemSetEnabled()来启用它。

Some more info and other options are available in the Daemons and Services Programming Guide.

“守护进程和服务编程指南”中提供了更多信息和其他选项。

#1


1  

Probably the best way of doing this now is to bundle the LoginItem inside the app bundle's Contents directory. You can then use SMLoginItemSetEnabled() to enable it.

现在最好的方法是将LoginItem捆绑在app bundle的Contents目录中。然后,您可以使用SMLoginItemSetEnabled()来启用它。

Some more info and other options are available in the Daemons and Services Programming Guide.

“守护进程和服务编程指南”中提供了更多信息和其他选项。