2

How can i programmatically in .net core, tell MacOS Catalina to startup my console application on system boot? I know that i can add program manually by Preferences:

Open System Preferences.
Go to Users & Groups.
Choose your nickname on the left.
Choose Login items tab.
Press “+” and choose the app you’d like add.
Then restart your Mac to see the changes.

But how to do this programmatically? Is this possible in .net core / zsh script?

stuartd
  • 70,509
  • 14
  • 132
  • 163
Paweł Kanarek
  • 2,317
  • 2
  • 10
  • 17
  • 2
    Perhaps you can get c# code to run the program to execute this: https://stackoverflow.com/a/13372744/2057955 – zaitsman Aug 13 '20 at 00:20
  • Thanks for idea, but my console application doesn't have info.plist file, and it's compiled as simple Unix executable. – Paweł Kanarek Aug 13 '20 at 00:37
  • 1
    plist is just XML aka just a text file. you can generate it in your c# code. – zaitsman Aug 13 '20 at 00:37
  • Okey i'll check that out :) – Paweł Kanarek Aug 13 '20 at 00:39
  • Note that if you place the .plist in ~/Library/LaunchAgents or /Library/LaunchAgents, it'll run as an "agent" under a logged in user (*if and when* a user logs in, not strictly at boot). If you place it in /Library/LaunchDaemons, it'll run as a "daemon", as root independent of whoever may or may not be logged in. Choose appropriately. – Gordon Davisson Aug 13 '20 at 04:16

1 Answers1

2

You would need to add the plist for the application to the LaunchAgents folder for the user. The path on the mac is /Library/LaunchAgents.

If you wanted it to start up before the user logs in on the Mac you would add it to the LaunchDaemons folder found at: /Library/LaunchDaemons

Laurent Gabiot
  • 1,251
  • 9
  • 15