0
mariano@host LaunchAgents % plutil local.test.plist 
local.test.plist: OK

But then:

mariano@host LaunchAgents % sudo launchctl load local.test.plist
Password:
/Users/mariano/Library/LaunchAgents/local.test.plist: Invalid property list

🤔

File in question:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
        <dict>
                <key>Label</key>
                <string>local.test.plist</string>
                <key>ProgramArguments</key>
                <array>
                <string>/bin/echo</string>
                <key>"Hello world"</key>
                </array>
                <key>StartInterval</key>
                <integer>1</integer>
        </dict>
</plist>

1 Answer 1

2

To start, the issue with your plist is that you have "Hello world" in <key> tags instead of <string> tags. While this is technically valid xml, it is not a valid plist, and certainly not a valid launchd configuration plist.

Invalid

    <key>ProgramArguments</key>
    <array>
    <string>/bin/echo</string>
    <key>"Hello world"</key>
    </array>

Valid

    <key>ProgramArguments</key>
    <array>
        <string>/bin/echo</string>
        <string>"Hello world"</string>
    </array>

You can actually have plutil fix this by using

plutil -convert xml1 local.test.plist

By default, the plutil command uses the -lint option by default if no other options are specified

From man plutil(1):

 - lint         Check the named property list files for syntax errors.  This is the default command option if none is specified.

My assumption is that this lint feature is not 100% fully baked and can miss some edge cases like this. It is likely just checking for matching opening and closing tags, but not the context of the keys and/or where they are.

Even though the documentation is getting a bit out of date these days, launchd.info is a great resource for launchd configuration and management. This this blog post has some great information about the more recent commands used to manage launchd.

2
  • Thank you so much @n8felton! Your reply is perfect for me to understand the concept, find my mistake and fix it. Also thank you so much for the recommendation for -convert option! I will surely make use of this every time I work with launchd, this is fantastic advice! Thanks again! Commented Apr 9, 2022 at 12:25
  • Hello @n8felton ! I don't think I can yet accept answers. I have to little points, so I cannot even upvote answers. Unless I'm missing something. Cheers. Commented Apr 12, 2022 at 22:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .