If you did set "show menu:" to "window", you'll have all the regular popups as defined by scripts (default or custom). Here you can make use of the $menu* identifiers. Example:
menu * {
-
fyi
.menu (item) = $menu : noop
.menutype = $menutype : noop
.menucontext = $menucontext : noop
$iif(($menucontext == treebar),this will show in treebar only) : echo -a something
$iif(($menucontext != treebar),this will never show in treebar) : echo -a something else
}
You cannot change the "system" menu though, but I think it shouldn't be accessible to scripts anyway.