Hi juliem31820066,
This is done through the Notify() callback. Basically, you put the desired code into some function, then add a notification for it to fire when a document is saved. Effectively, the script as a whole is always running with Notify() listening, which then triggers the desired functionality when a document is saved.
I have a sample here:
FrameMaker ExtendScript Samples - West Street Consulting
It is 06.01 - NOTIFICATION_-_Notify_on_doc_open_and_close. This script shows an example of code execution when a document is opened or closed. You could very easily convert it to a save action by changing "FA_Note_PreQuitDoc" and "FA_Note_PostOpenDoc" in the script to "FA_Note_PreSaveDoc" and "FA_Note_PostSaveDoc".
Congratulations on getting a script to work, especially if this is your first time. I remember the first FDK client I got to work. All it did was toggle element brackets with a keyboard shortcut, but it seemed as if I were Hercules and had opened a massive portal to a forbidden paradise. In retrospect, it was a big deal. The ability to customize my tools has made all the difference in my career.
Russ