How it works
What tloop writes, what launchd runs, and where each piece lives.
launchctl list | grep com.tloopThat lists every tloop task launchd has loaded right now. tloop is a thin layer over launchd: it writes the files, and launchd does the scheduling.
From add to a log file
tloop add saves the task in ~/.tloop/config.json, then writes a launchd job and loads it. On your Mac, launchd starts the job com.tloop.task followed by the task ID, once when it loads and then every interval. Each time, runner.sh reads the task, skips the run when the task is stopped or outside its hours, moves to the task's folder, and runs the command with your shell. The output and the exit code go to one log file per run in ~/.tloop/logs.
The files
| File | What's in it |
|---|---|
~/.tloop/config.json | Every task: ID, name, command, interval, folder, hours, whether it's enabled, and when it was made. |
~/.tloop/runner.sh | The script every run goes through. tloop rewrites it each time it writes a launchd job. |
~/Library/LaunchAgents/com.tloop.task.<id>.plist | The launchd job for one task. |
~/.tloop/logs/<id>/ | One log file per run, plus launchd-err.log. See Logs. |
The launchd job
tloop add, edit and start write the task's plist and run launchctl load on it. The plist sets:
| Key | Value |
|---|---|
Label | com.tloop.task.<id> |
ProgramArguments | /bin/bash, the runner script and the task ID |
StartInterval | The interval in seconds. 15m is 900. |
RunAtLoad | true, so the task runs once as soon as it's loaded |
EnvironmentVariables | PATH, HOME and SHELL, copied from your terminal when you ran the command |
StandardErrorPath | ~/.tloop/logs/<id>/launchd-err.log |
launchd loads every plist in ~/Library/LaunchAgents when you log in, which is why tasks come back after a restart.
Each run
launchd starts runner.sh with the task ID. The runner:
- Reads the task from
~/.tloop/config.jsonwith/usr/bin/python3. - Skips the run when the task is disabled, or when the hour is outside
--hours. - Moves to the task's folder, if it has one.
- Runs
"$SHELL" -c "<cmd>", so the command gets the same shell you use, and appends its output to the run's log file. - Writes the exit code to the log and exits with it.
Because the runner reads the config on every run, a change to a task's command, folder or hours in config.json applies from the next run. A new interval needs tloop edit, because launchd only reads the interval from the plist.
Stop and remove
tloop stop unloads the job and marks the task disabled, but leaves its plist where it is. tloop remove unloads the job, deletes the plist and takes the task out of config.json. The logs stay in both cases.