Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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 > 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 …

<?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>Disabled</key>
    <false/>
    <key>Label</key>
    <string>de.tweh.SaveCSStoCSSPHP</string>
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/script/copy.sh</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/path/to/folder/file.a</string>
    </array>
</dict>
</plist>

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
share|improve this question
    
Have you looked at the Console application to see what the logs say? –  ayaz Jun 15 '13 at 17:41
    
@ayaz: Not yet, but it isn’t helpful (for me) … see my edit … –  Tobi Jun 15 '13 at 22:44
    
@ayaz: Thanks that led me to the solution :-) –  Tobi Jun 16 '13 at 10:23
add comment

closed as too localized by Mark, patrix Jun 16 '13 at 11:37

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 0 down vote accepted

I found the error: I used chmod -x instead of chmod +x. Now it works fine :-)

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.