Ending spells by attacking

is it possible to set a spell so that it ends when the character attacks?

------------------