我有一个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
更多推荐
如何在启动时启动应用程序
发布评论