Need to start the Mac application automatically

I am developing the application in Mac. My requirement is to start the application automatically when user login.

  1. I have tried adding the plist file in launch agents, But it doesn't achieve my requirement.

Please find the code added in the launch agents

<?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.sftk.secure</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Testing.app/Contents/MacOS/Testing</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
</dict>
</plist>
  1. I have tried by adding manually in the setting, but it was opened sometimes and closed suddenly. On open manually it works.

Please provide a solution to start the application automatically on system starts

Answered by DTS Engineer in 847993022

The best way to do this is with the SMAppService API. It supports a bunch of different registration models, including:

  • Register your main app as a login item (mainApp)
  • Register an embedded app as a login item (loginItem(identifier:))
  • Register an embedded program as a launchd agent (agent(plistName:))
  • Or as a launchd agent (daemon(plistName:))

The best option depends on the specific UI you want. Registering your main app as a login item might make sense in some circumstances, but I generally find it’s better to use a separate launchd agent and then have your main app act as a UI for that agent. That allows you to continue providing your service even if the user quits your main app.

Share and Enjoy

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

The best way to do this is with the SMAppService API. It supports a bunch of different registration models, including:

  • Register your main app as a login item (mainApp)
  • Register an embedded app as a login item (loginItem(identifier:))
  • Register an embedded program as a launchd agent (agent(plistName:))
  • Or as a launchd agent (daemon(plistName:))

The best option depends on the specific UI you want. Registering your main app as a login item might make sense in some circumstances, but I generally find it’s better to use a separate launchd agent and then have your main app act as a UI for that agent. That allows you to continue providing your service even if the user quits your main app.

Share and Enjoy

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

Need to start the Mac application automatically
 
 
Q