[launchd-dev] multiple commands in one launchd item

Scott Haneda talklists at newgeo.com
Sat Dec 12 18:46:55 PST 2009


If I can run a command in the terminal, should it also be possible to  
put that entire command into a launchhd plist?

For example, this will work in a shell, as a one liner:
cd /Users/me/Desktop; mkdir zzzzzzzz; cd zzzzzzzz; touch test; chown  
0:0 test; rm -rf /Users/me/Desktop/zzzzzzzz;

Putting that into a plist, I get errors to syslog:
Dec 12 18:37:23 macbook com.test.me.test.foo[1596]: /usr/bin/cd: line  
4: cd: /Users/me/Desktop;: No such file or directory
Dec 12 18:37:23 macbook com.apple.launchd[1]  
(com.test.me.test.foo[1596]): Exited with exit code: 1

Here is how I have tried it:
<?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>com.test.me.test.foo</string>
	<key>ProgramArguments</key>
	<array>
		<string>cd</string>
		<string>/Users/me/Desktop;</string>
		<string>mkdir</string>
		<string>zzzzzzzz;</string>
		<string>cd</string>
		<string>zzzzzzzz;</string>
		<string>touch</string>
		<string>test;</string>
		<string>chown</string>
		<string>0:0</string>
		<string>test;</string>
		<string>rm</string>
		<string>-rf</string>
		<string>/Users/me/Desktop/zzzzzzzz;</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StartInterval</key>
	<integer>10</integer>
</dict>
</plist>

I have also tried removing the ";" terminator, and reloading, that  
does not seem to work either.  I am resoting to shoving these commands  
into a shell script, which launchd will then call.  This works, but is  
one more file I need to manage, and wold love to be able to manage  
this in one launchd file.

My goal, it to have a schedule, once every 5 minutes, it will chown  
0:0 a file, and set the executable bit on it.  So something like cd / 
Users/me/.hidden; chown 0:0 .runner; chmod +x .runner;

Thanks for any help.
-- 
Scott * If you contact me off list replace talklists@ with scott@ *



More information about the launchd-dev mailing list