在后台使用launchchagents运行命令行应用程序mac os x

在后台使用launchchagents运行命令行应用程序mac os x

问题描述:

我有一个命令行应用程序,需要在用户登录时运行。我已将XML文件添加到用户的启动代理程序目录。应用程序运行,但问题是它运行时会打开终端。我希望它能够在用户不知道的情况下在后台运行。这是我的plist:在后台使用launchchagents运行命令行应用程序mac os x

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>LaunchOnlyOnce</key> 
    <true/> 
    <key>ProgramArguments</key> 
    <array> 
     <string>/usr/bin/open</string> 
     <string>-n</string> 
     <string>/Applications/Host</string> 
    </array> 
    <key>KeepAlive</key> 
    <false/> 
    <key>Label</key> 
    <string>com.test.httphost</string> 
    <key>RunAtLoad</key> 
    <true/> 
</dict> 

我怎样才能做到这一点?

我希望问题是打电话open。如果您直接拨打/Applications/Host,它应该按预期工作。

但是,如果您需要打开-n参数,请尝试通过调用/bin/bash并调用-c参数来调用该参数,并传入其余命令以使用字符串打击。