greasepencil draw help

I was wondering how to have the greasepencil execute a script after exiting continuous draw session or pressing esc.

Lets say I check continuous drawing and click draw, after i’m done I would click esc to end freehand session, and have a script run afterwards.