A Folder Action can be configured to execute whenever a folder is opened, closed, or moved. In addition, Folder Actions can be configured to trigger when items are placed in, or removed from a folder.
You can see the syntax in the Standard Additions dictionary, under the Folder Actions Suite.