views:

196

answers:

2

I'm attempting to write a launchd agent that runs a simple application for every user that logs in to the Mac OS X system.

I have created a file named com.mycompany.myapp.plist and placed it in /Library/LaunchAgents. The contents of that file are:

{
    LimitLoadToSessionType = "Aqua";
    StartInterval = 10;
    OnDemand = NO;
    KeepAlive = YES;
    RunAtLoad = YES;
    Label = "com.mycompany.myapp";
    Program = "/Users/thomi/myapp";
    ProgramArguments = (
        "/Users/thomi/myapp",
        "-l",
        "-d",
    );
}

Initially I didn't have the StartInterval key set, since I thought the agent would start automatically. The problem is that the agent does not start unless I manually issue the following two commands:

launchctl load -S Aqua -D all
launchctl start com.mycompany.myapp

Firther, when I run launchctl list com.mycompany.myapp I get the following output:

{
    "Label" = "com.mycompany.myapp";
    "LimitLoadToSessionType" = "System";
    "OnDemand" = true;
    "LastExitStatus" = 0;
    "TimeOut" = 30;
    "Program" = "/Users/thomi/myapp";
    ProgramArguments = (
        "/Users/thomi/myapp",
        "-l",
        "-d",
    );
};

Notice that the LimitLoadToSessionType parameter has changed.

Am I missing something here? Is there a different mechanism to start agents like this? Why has the LimitLoadToSessionType property changed?

A: 

Not sure if it's the problem, but I think you shouldn't be specifying both OnDemand/RunAtLoad and KeepAlive together. As I understand the documentation, the KeepAlive key replaces the OnDemand/RunAtLoad combo.

http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html#SECCODINGRECOMMENDATIONS

Ken Aspeslagh
I'm afraid that doesn't make any difference.
Thomi
A: 

Found the problem - apparently launchd doesn't work properly with the old-style plist files. It loads OK, but won't run anything. Re-creating the above file as a new-style XML file solved the issue.

Thomi