Well I already told you the theorical part.
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.