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.

How to execute a Folder Action or another Automator script when I make changes to a folder? And by changes I mean not just deleting or inserting new file, the most important for me is when the content of a file is changed the action will be triggered.

share|improve this question
    
    
You have two awesome answers. Do either help you out? –  bmike Apr 13 '13 at 11:09

2 Answers 2

This kind of requirement goes beyond the simple fsevents hooks exposed as Folder Actions. I’d recommend using Paul Kim’s Hazel, which will allow you to create “watch and react” rules of almost unlimited granularity and complexity.

share|improve this answer

Using launchd, you could save a property list like this in ~/Library/LaunchAgents/ and load it with something like launchctl load ~/Library/LaunchAgents/automator_test.plist or by logging out and back in.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>automator_test</string>
    <key>ProgramArguments</key>
    <array>     
        <string>automator</string>
        <string>/Users/username/Desktop/Test.workflow</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/Users/username/Desktop/</string>
    </array>
    <key>StartInterval</key>
    <integer>0</integer> <!-- run at most every 0 seconds, by default 10 -->
</dict>
</plist>

Launchd only detects changes to files when they are saved atomically (or deleted and recreated every time they are saved). Most OS X apps perform atomic saves, but for example TextMate and vim don't.

share|improve this answer
    
I haven't tested it yet al test it when I get home. But will it make it automatically every time I save changes to a file inside the folder? I started to read something about launchctl not being the recommended app/service for that, but I cannot remember where I read it. –  tenshimsm Jun 19 '12 at 20:48
    
I did that and nothing is happening –  tenshimsm Jun 20 '12 at 2:14
    
I tested it again and it worked for me. Did you replace username? You have to launchctl unload $path && launchctl load $path to apply changes. –  ؘؘؘؘ Jun 20 '12 at 4:28
    
Thank you, but, it doesn't work the way I want. It does what Folder Actions does, which is triggered if I insert, move or delete something inside the folder. I edited a HTML file inside the folder and nothing happened. And it is not recursive. –  tenshimsm Jun 20 '12 at 22:05
    
You're right that it's not recursive, but it should be triggered when files are modified or files or folders are moved, deleted, or created. –  ؘؘؘؘ Jun 21 '12 at 11:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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