Try the same thing with any auto cast ability that isn't attack related. Not because that's the problem, but it will just be better if it doesn't have to be an attack.
What are you trying to do so far, because it would just simply be a when unit casts event and then you take gold from owning player of titan and add the same amount to owning player of triggering unit.
You're familiar with what a dummy spell is right?? when you take away all non-triggered effects from a spell??
You use the "A unit is issued a order" event. Now check if the order was your ability ON ID (go check whats your ON/OFF ID in the object manager). If it is, you set a boolean's value to be true.
Now, whenever that unit attacks with its boolean true - do your actions.
When the unit is issued the "OFF" order, you make the boolean false.
You'll also need a trigger to detect if the unit has mana or not and disable it according to that.
If you want it to look good you will also need a Hit Detection system (not recommnded in GUI).
If you want it to be MUI (any unit can cast it at any time) and not PUI (one unit per player), you must use JASS.
[Edit]Don't listen to this nonsense I just wrote !
When a unit is issued the ON order, you change its custom value to someNumber (some number...), now whenever a unit attacks with that custom value - you do your actions.
When he is issued the off/has no mana, you change his custom value to something else.