I am not sure this can be done even with a complex script.
I would think you would need a custom table or file to track the alarms as they come in.
Set the original alarms invisible and have logic to create a new alarms.
all of which could potentially severely slow down your alarm processing depending on how it is implemented.
If the requirement was to say send only one email or to only create one ticket in a service desk you might be able to do that with a set of triggers or script a little easier...
But I think you will be hard pressed to accomplish this the way UIM alarms are currently structured.
Maybe others have some ideas......