Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Launchd wildcard characters System
One of the occasional irritations of working with launchd is that it doesn't naturally expand shell wildcard characters (~,*,?,...). This means that full paths have to be spelled out for all files: an annoyance at best, and an obstacle when commands need to select specific groups of files or do work across different home folders. For example, a command to clean certain files from a user folder when any user logs in, which is simple enough to write in the shell -- rm -f ~/Folder/*.xxx -- fails when written into a launchd plist.

However, launchd can expand shell characters, but expansion is disabled by default (assumedly for performance reasons). To enable expansion, add an EnableGlobbing key to the plist and set its value to true. The plist for the above shell command, then, would be:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
Which should work as expected.

Unfortunately, expansion is only enabled for strings in the Program or ProgramArguments keys, not for other keys (such as the WatchPaths, QueueDirectory, or WorkingDirectory keys), so this can't be used to set up wildcard triggers.

[crarko adds: I haven't tested this one.]
  • Currently 3.85 / 5
  You rated: 3 / 5 (13 votes cast)

Launchd wildcard characters | 4 comments | Create New Account
Click here to return to the 'Launchd wildcard characters' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Launchd wildcard characters
Authored by: koehn on Oct 06, '10 11:12:13AM

You also cannot redirect stdin or stdout from launchd. You can, however, launch a shell script to do these things. Simply write your script, put it wherever you deem appropriate, and have your launchd document run it.

[ Reply to This | # ]
Launchd wildcard characters
Authored by: tedw on Oct 06, '10 02:01:45PM
Interestingly, launchd.plist has keys for StandardInPath, StandardOutPath, and StandardErrorPath (I had a dim memory of those when I read your post, and had to go check the man page). These take filepath strings, so it seems you actually can do redirection straight from the plist. I've never used them, though, so I can't say if there are any restrictions, limitations, or gotchas waiting in the wings.

[ Reply to This | # ]
Launchd wildcard characters
Authored by: DougAdams on Oct 06, '10 11:29:33AM

Great tip! Thanks.

Doug's AppleScripts for iTunes

[ Reply to This | # ]
Launchd wildcard characters
Authored by: ambrose on Oct 11, '10 01:28:08PM

For my part, this is one of the year's 10 most useful hints. Thank you for posting it.

[ Reply to This | # ]