Skip to Content
tloop

How it works

What tloop writes, what launchd runs, and where each piece lives.

launchctl list | grep com.tloop

That 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

FileWhat's in it
~/.tloop/config.jsonEvery task: ID, name, command, interval, folder, hours, whether it's enabled, and when it was made.
~/.tloop/runner.shThe script every run goes through. tloop rewrites it each time it writes a launchd job.
~/Library/LaunchAgents/com.tloop.task.<id>.plistThe 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:

KeyValue
Labelcom.tloop.task.<id>
ProgramArguments/bin/bash, the runner script and the task ID
StartIntervalThe interval in seconds. 15m is 900.
RunAtLoadtrue, so the task runs once as soon as it's loaded
EnvironmentVariablesPATH, 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:

  1. Reads the task from ~/.tloop/config.json with /usr/bin/python3.
  2. Skips the run when the task is disabled, or when the hour is outside --hours.
  3. Moves to the task's folder, if it has one.
  4. Runs "$SHELL" -c "<cmd>", so the command gets the same shell you use, and appends its output to the run's log file.
  5. 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.

On this page