How to copy file content automatically to another file when saved? I’d like to automatically copy the contents of a file file.a to file.a.b whenever file.a is saved by any program. The following is what I tried so far with a LaunchAgent, but it doesn’t work yet.

1. Create script to copy the file contents

#!/bin/bash
say "Script is running"
cd /path/to/folder
cat file.a &gt; file.a.b


make it active with chmod -x copy.sh. This script works when I run it manually via sh script.sh or with a global hotkey from Alfred.

2. Create a LaunchAgent
I build it with Lingo but saved it manually since Lingo won’t save the file …

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Disabled&lt;/key&gt;
    &lt;false/&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;de.tweh.SaveCSStoCSSPHP&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/path/to/script/copy.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;WatchPaths&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/path/to/folder/file.a&lt;/string&gt;
    &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;


3. Save LaunchAgent
I saved the agent as ~/Library/LaunchAgents/de.tweh.DoCopy

4. Restart
Restart my Mac to activate the LaunchAgent.

What am I doing worg?

Edit
The Console gives this (useless?) error message:

16.06.13 00:44:04,005 com.apple.launchd.peruser.502[153]:
(de.tweh.DoCopy[326]) Job failed to exec(3) for weird reason: 13
I found the error: I used chmod -x instead of chmod +x. Now it works fine :-)