A Simple Launchd Tutorial

touch ~/demo/main.js
console.log("Hello", Date.now())
touch ~/Library/LaunchAgents/com.demo.daemon.plist
  • The daemon will start whenever the user logs in.
  • It will execute every 20 seconds.
  • It will output to some log files (very useful for debugging).
  • It will set the environment path (useful if your program uses other commands from usr/local/bin).
  • The command will execute in the /Users/chet/demo directory.
  • And the command is /usr/local/bin/node main.js.
launchctl load ~/Library/LaunchAgents/com.demo.daemon.plist
launchctl unload ~/Library/LaunchAgents/com.demo.daemon.plist
cat ~/demo/stderr.log
Hello 1525844666922
Hello 1525844687004
Hello 1525844707086
Hello 1525844727169
Hello 1525844747245
Hello 1525844767333
Hello 1525844787419
Hello 1525844807505
Hello 1525844827596
Hello 1525844847681




Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chet Corcos

Chet Corcos

More from Medium

When Faith Is Critical

The graphic contains four, empty speech bubbles in the background. In the foreground is text framed by a white square that reads, “#31DaysIBPOC.”  Underneath this are two lines that state, “Celebrating the teacher voices of Indigenous, Black, & People of Color this May!” The bottom of the graphic lists the following information, “Hosted by @TchKimPossible @triciaebarvia.”

Geography is destiny.

Mental health- SolGirls