Instead of starting the emulator directly from AM, you could start a script that starts the emulator. In that script, you could run whatever you want after the emulator. Just an idea I didn't test myself, yet.
edit: Alas, it's not that easy. AM seems to check when the emulator exits, so any command after it isn't executed. I tested it with a simple script that writes the time before and after mame into a file. It works when started directly, but if started from AM, the end time is omitted.
Which operating system do you use?