Run launchd script at login (macOS)

Veröffentlicht von philipp am

First of all create your bash script and place it somewhere.

Next think of a name in the following reverse domain notation com.mycompanyname.mydepartment.mytaskname.plist and create the property list file (.plist) with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Now place com.mycompanyname.mydepartment.mytaskname.plist in ~/Library/LaunchAgents and run in terminal:
launchctl load ~/Library/LaunchAgents/com.mycompanyname.mydepartment.mytaskname.plist

This tells launchd to load the task and will run it immediately.

To remove the task from launchd run:

launchctl unload ~/Library/LaunchAgents/com.mycompanyname.mydepartment.mytaskname.plist

You can check if it is loaded with the command by entering:
launchctl list | grep com.mycompanyname.mydepartment.mytaskname

Install Sleepwatcher and fswatch:

brew install sleepwatcher

brew install fswatch

If your script does not run after entering the commands above:

  • complement any executable name by its full path. E.g. I had issues running fswatch, so I had to replace fswatch by /usr/local/bin/fswatch
  • Also it could be that launchd closes the tasks you started in your script when it reaches its end. Then you just have to add following code at the end of your script:
    while : ; do
    sleep 1d

Run launchctl every hour:



Kategorien: macOS

0 Kommentare

Schreibe einen Kommentar


Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert