Without knowing anything else, one way could be to use DanNet. It has the ability to create observers, which can monitor a TLO and report back to you.
An example of observers in action can be found in the Boxhud Lua.
As to the other half of the problem you would need an event, macro, Lua, whatever, to be checking for that spell to be active and then do the thing.