Convert Launchd WatchPaths and QueueDirectories to JSON
Convert launchd plist files with WatchPaths and QueueDirectories to JSON. Learn how file-watching triggers are represented in both formats.
Detailed Explanation
File System Triggers in Launchd
Launchd can trigger jobs based on file system changes using WatchPaths (triggered when paths are modified) and QueueDirectories (triggered when directories become non-empty).
Plist Structure
<dict>
<key>Label</key>
<string>com.example.file-processor</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/process-files.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/var/data/incoming</string>
<string>/var/data/config.json</string>
</array>
<key>QueueDirectories</key>
<array>
<string>/var/spool/jobs</string>
</array>
<key>ThrottleInterval</key>
<integer>10</integer>
<key>StandardOutPath</key>
<string>/var/log/file-processor.log</string>
<key>StandardErrorPath</key>
<string>/var/log/file-processor-error.log</string>
</dict>
JSON Output
{
"Label": "com.example.file-processor",
"ProgramArguments": ["/usr/local/bin/process-files.sh"],
"WatchPaths": ["/var/data/incoming", "/var/data/config.json"],
"QueueDirectories": ["/var/spool/jobs"],
"ThrottleInterval": 10,
"StandardOutPath": "/var/log/file-processor.log",
"StandardErrorPath": "/var/log/file-processor-error.log"
}
Array of Strings Pattern
Both WatchPaths and QueueDirectories are arrays of file path strings. This is one of the most common patterns in launchd plists. The JSON representation is straightforward and works well with JSON manipulation tools.
ThrottleInterval
The ThrottleInterval is an <integer> specifying the minimum seconds between job launches. This prevents rapid-fire triggering when multiple file changes happen in quick succession. In JSON, it becomes a plain number.
Combining Triggers
A single launchd job can use WatchPaths, QueueDirectories, StartCalendarInterval, and StartInterval simultaneously. The job runs when any trigger fires. The JSON format makes it easy to see all triggers at a glance.
Use Case
Helpful for DevOps engineers documenting file-watching triggers in launchd jobs, or for migration scripts that convert macOS-specific file processing pipelines to cross-platform JSON configurations.