Is there a folder action that tells you when a file has been modified?

I need to copy a file from a folder to another whenever it’s been modified. I thought it would be easy, there must be a Folder Action that can do it. Is there some kind of script that can do this automatically?

I think the easiest way to do this is with launchd

<?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.tjluoma.copy-on-change</string>
	<key>ProgramArguments</key>
	<array>
		<string>/bin/cp</string>
		<string>-f</string>
		<string>/path/to/original/file.ext</string>
		<string>/path/to/where/you/want/it/copied/file.ext</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/tmp/com.tjluoma.copy-on-change.log</string>
	<key>StandardOutPath</key>
	<string>/tmp/com.tjluoma.copy-on-change.log</string>
	<key>WatchPaths</key>
	<array>
		<string>/path/to/original/file.ext</string>
	</array>
</dict>
</plist>

Save that file to ~/Library/LaunchAgents/com.tjluoma.copy-on-change.plist

Replace both instances of /path/to/original/file.ext with the actual path to the “original” file, and replace /path/to/where/you/want/it/copied/file.ext with the actual path where you want it copied to.

Note that the destination folder /path/to/where/you/want/it/copied/ must already exist for this to work, and obviously the “backup” copy will be overwritten on every change.

Once it is ready to go, enter this in Terminal.app:

launchctl load ~/Library/LaunchAgents/com.tjluoma.copy-on-change.plist

Then change the file and see if it is copied.

If it is not, check /tmp/com.tjluoma.copy-on-change.log for any error messages.

WOW!
Thanks so much, it worked like a champ:)

Great! Glad to help.