What is a folder action and how do I use one?

Folder Actions are special scripts which can be attached to any folder that force events to take place when items are added or removed from that folder. Events can also fire when the related folder is opened, closed or moved. In pre-OSX systems, the folder had to be opened in order to respond to events.

Here is a simple example script:

on adding folder items to thisFolder after receiving addedItems
	repeat with anItem in addedItems
		tell application "Finder"
			set comment of anItem to "Hello!"
		end tell
	end repeat
end adding folder items to

When attached to a folder, this script would change the comment of anything added to it to “Hello!”. Now save your script and attach it to a folder (read in this same category “How do I attach a Folder Action to a folder?”) and you are done!