如何在启动时启动应用程序

编程入门 行业动态 更新时间:2024-10-24 04:33:26
本文介绍了如何在启动时启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个OSX项目(objective-c),我想在启动时运行它.

I have an OSX project (objective-c) and I'd like to run it on startup.

意思是,我想编写一些代码植入我的应用程序,以便它在启动时运行.这样,每当用户首次运行我的应用程序时,它将始终在该用户启动时启动.

Meaning, I want to write some code that plants my application so that it'll run upon startup. So that whenever a user will run my application for the first time it will always launch on startup for that user.

我该怎么做?

我们非常感谢您的帮助!

Any help is highly appreciated!

推荐答案

您必须使用启动代理.

创建这样的XML文件,并将其放置在〜/Library/LaunchAgents(对于单个用户)或/Library/LaunchAgents(对于所有用户)中.

Create an XML file like this one and place it in either ~/Library/LaunchAgents (for a single user) or /Library/LaunchAgents (for all users).

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "www.apple/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.example.your.program</string> <key>ProgramArguments</key> <array> <string>--some-arg</string> <string>--some-other-arg</string> </array> <key>KeepAlive</key> <true/> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> <key>StandardErrorPath</key> <string>/dev/null</string> <key>StandardOutPath</key> <string>/dev/null</string> </dict> </plist>

然后重新启动启动代理,以使用launchctl load ~/Library/LaunchAgents/com.example.your.program.plist

Then restart the launch agent to load your file with launchctl load ~/Library/LaunchAgents/com.example.your.program.plist

更多推荐

如何在启动时启动应用程序

本文发布于:2023-11-05 08:29:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560366.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:启动时   应用程序   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!