In Windows it is possible to create an application that can be installed as a service. This type of application is called a Windows Service. What would be the equivalent of services on Mac OS X? How are they implemented and where to start to learn about it?
I would like to create a service to execute a task automatically, and starting and stopping it on demand.
You need to become friends with
launchd. You need to createlaunchdconfiguration files that are placed in one of five locations:~/Library/LaunchAgents: Per-user agents provided by the user./Library/LaunchAgents: Per-user agents provided by the administrator./Library/LaunchDaemons: System-wide daemons provided by theadministrator.
/System/Library/LaunchAgents: Per-user agents provided by Mac OS X./System/Library/LaunchDaemons: System-wide daemons provided by Mac OSX.
A daemon is a system-wide service of which there is one instance for all clients. An agent is a service that runs on a per-user basis.
Configuration files are in the form of a property list.
The syntax is simple but it’s easy to get it wrong. The Wikipedia article has a good summary of the options if the man page is not to your liking.
Essentially, what you do is install your actual command-line tool (your service) somewhere and then create a
launchdconfiguration plist and place it in one of the above locations. You can configure the plist so thatlaunchdruns your service at launch or periodically, or in response to various actions (such as the contents of a folder changing).There is a good in-depth article here.