How to make a toggle switch in mel?

I have a Hot key for my Outliner, but I want to make it toggle ON and OFF with the Hot key. I managed to do this with many other functions, but seem to be having problems with Outliner. I usually copy mel commands onto the shelf and it works OK, but it does not seem to be working with Outliner.

Kori

i have this mapped to "o"

global proc outlinerWinToggle()
{
if ( window -exists outlinerPanel1Window )
deleteUI -window outlinerPanel1Window;
else
tearOffPanel "Outliner" "outlinerPanel" false;
}

I copy and pasted into my script editor and then dragged it on to my Shelf, but it did not work for me.

Kori

You need to remove the "global proc outlinerWinToggle()" line for it to work on your shelf.

Or save a global porc in a mel file that has the same name.mel in your script directory and then just paste outlinerWinToggle(); in your shelf.

Or put a call to outlinerWinToggle(); after the definition... but theres little point define it over and over again.