Is it possible to capture the triggered event of the button that appears on the top right corner of a Mac application (the one that shows/hides the toolbar)?

What I would like to do is to capture the event and do something custom with it, for example I want to link its functionality to other widgets and not the toolbar.