In maya there is a script node which can be used to store and execute mel scripts within the Maya scene. These scripts can either be called manually, or on specific key events such as file open/close, render start, render frame start etc.
Each script node can contain two scripts held in the "before" and "after" attributes of the node. This allows you to create a script to be run before a render to set up any default settings etc, then at the end you can process the data. In the case of file load, the before script is called when the file is opened, the after script is called when the file closes.
Note: script nodes are not the same thing as expressions. Expressions should be used when controlling objects within your scene. Script nodes are more useful to help impliment features for a tool rather than manipulate key objects within the scene.