LaunchAgents not work by SMAppService.agent().register() API

After app running, here is some scenarios:

register a LaunchAgent

let service = SMAppService.agent(plistName: "com.zhangeek.agent.plist")
do {
    try service.register()
    print("Successfully registered \(service)")
}catch {
    print("Unable to register \(error)")
}

Property List file Contents/Library/LaunchAgents/com.zhangeek.agent.plist

<?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>Label</key>
    <string>com.zhangeek.agent</string>
    <key>BundleProgram</key>
    <string>Contents/Resources/server</string>
    <key>StandardOutPath</key>
    <string>/tmp/agent.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/agent.log</string>
</dict>
</plist>

server executable binary built by golang

func main() {
   for {
      fmt.Println(time.Now().Format(time.RFC3339))
      time.Sleep(1 * time.Second)
   }
}

My Question: why /tmp/agent.log is empty and launchAgent not found in result launchctl list.

Answered by DTS Engineer in 741549022

why /tmp/agent.log is empty

I would expect that to be empty because, based on the steps you posted, the agent is configured to launch on demand and there’s nothing that generates demand to trigger the launch.

and launch agent not found in result launchctl list

I don’t have a ready explanation for that. However, I do have some detailed steps that explain how I tested this feature. See this post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

why /tmp/agent.log is empty

I would expect that to be empty because, based on the steps you posted, the agent is configured to launch on demand and there’s nothing that generates demand to trigger the launch.

and launch agent not found in result launchctl list

I don’t have a ready explanation for that. However, I do have some detailed steps that explain how I tested this feature. See this post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

LaunchAgents not work by SMAppService.agent().register() API
 
 
Q