← Mac Change Notes

LaunchAgent Paths With Spaces

Put each LaunchAgent argument in a separate ProgramArguments string. Keep spaces inside that string without adding shell quotes or backslashes; those characters can become part of the filename.

In this article

Start with the argument array

If a command works in Terminal but fails when launched as your own background job, inspect the plist before changing permissions. In Terminal, your shell turns a command line into arguments. A ProgramArguments array supplies those arguments directly.

For example, this Terminal command asks cat to read one file:

/bin/cat "/Users/example/Reports/Report One.txt"

The shell removes the surrounding quotes while preserving the space. The equivalent ProgramArguments array contains two strings, in this order:

Array entryLiteral string value
First: executable/bin/cat
Second: filename/Users/example/Reports/Report One.txt

These are the argument values, not a complete job configuration. Replace the illustrative path with the file you actually intend to read. Do not put quote characters around the path inside its <string> element, and do not write Report\ One.txt there to escape the space.

Apple’s archived launchd configuration guide shows a program and its arguments as separate array entries. The current local reference is man launchd.plist; it describes ProgramArguments as an argument vector passed to the new process.

Apple’s launchd guide showing Label and ProgramArguments as separate configuration keys.

Apple’s Creating Launch Daemons and Agents, captured November 15, 2026. The configuration table distinguishes the job label from the arguments used to start it. This is archived documentation; the experiment below checks actual behavior on a named macOS version.

Keep three kinds of syntax separate

There are three different parsers to consider: the plist reader, a shell if you explicitly start one, and the program receiving the arguments.

Where the text appearsWhat separates arguments?How to handle a space
A command typed into TerminalThe shell’s parsing rulesQuote or escape it as required by that shell
Separate ProgramArguments stringsThe array entriesLeave the space inside one string
A shell command supplied after -cThat explicitly invoked shellApply shell syntax inside that command string

XML escaping is a separate issue. A literal ampersand in an XML string needs the appropriate XML representation, such as &amp;. That does not turn the string into a shell command. A property-list editor can handle serialization without requiring you to hand-write every entity.

Likewise, the receiving program may interpret its own options or patterns. An argument reaching a tool unchanged does not mean that tool will treat it as an ordinary filename. Check the command’s documented argument format.

What four disposable jobs received

On November 15, 2026, we ran four one-shot user LaunchAgents on macOS 15.7.5, Apple Silicon. Each launched /bin/sh with a small script that printed its argument count and each received value. The script did not evaluate the arguments as commands.

We created two harmless text files, Report One.txt and Report Two.txt, in the test working directory. The observed results were:

Input in the plistWhat the script printed
Two strings: Report One.txt and Report Two.txtTwo arguments, with both internal spaces preserved
Strings containing "Report One.txt" and Report\ One.txtQuote characters and the backslash remained in the values
Five strings: *.txt, $HOME, ~, > and |Five literal arguments; no variable expansion, redirection or pipe execution
*.txt and $HOME, with EnableGlobbing set to trueBoth strings remained literal in this test

The vertical bar in the third row represents the single pipe character. All four jobs ran, produced output and were unloaded afterward. We verified that their registrations were absent. We changed no existing job, session-wide environment or system daemon.

The fourth result deserves care. The local manual documents an EnableGlobbing key, but it did not expand the wildcard in our tested configuration. This observation does not establish behavior on every macOS release. More importantly, globbing is not a promise of full shell parsing. Use explicit filenames or a deliberately written script when the task requires expansion.

Use a script when the task needs shell behavior

Putting >, | or && into separate strings does not create a redirection, pipeline or conditional command by itself. Those constructs need a shell to interpret them. A short script with a known interpreter is often easier to inspect than several layers of quoting inside a plist.

Apple’s script-management guide describes using launchd to run shell scripts. If you invoke a shell with -c, the following argument is shell command text. That is a different arrangement from an executable followed by a list of literal file arguments.

Avoid assembling such command text from untrusted filenames or external input. Keep data as arguments whenever the program supports that. For ordinary logging, inspect the job’s StandardOutPath and StandardErrorPath instead of adding a shell just to imitate redirection. The LaunchAgent logging guide covers missing output destinations separately.

Verify the smallest correction

For a job you own, save the original plist and inspect the array with plutil -p "/path/to/job.plist". Check syntax using plutil -lint "/path/to/job.plist". A successful lint result confirms a parseable property list; it does not prove that its paths exist or the command will succeed.

Before reloading, establish whether repeating the task is safe. A registered job may still use its previously loaded configuration, and a RunAtLoad job can execute immediately when registered again. Reload only the specific job you intended to change, then check its actual output or result.

If removing extra quotes does not resolve the problem, follow the evidence to the next layer. A missing executable belongs to the PATH and command lookup diagnosis. A relative data path belongs to the working-directory diagnosis. Neither is repaired merely by changing quotation marks.

For an unfamiliar vendor helper, use the developer’s supported configuration or repair process. The useful test here is narrow: confirm exactly which arguments the intended process receives before changing how the rest of the Mac launches software.