There are a couple ways this could be accomplished.
Each relies on deciding if the current script is the topmost loaded:
alias -l showmenu {
var %competing = FULL_FILE_PATH
if ($script(%competing) == $null) return 1
var %i = 1
while (%i <= $script(0)) {
if ($script(%i) == $script) { return 1 }
if ($script(%i) == %competing) { return 0 }
inc %i
}
}
The first way to display the menu involves a conditional in the menu event, it is evaluated each time you call for the menu:
menu @window {
$iif($showmenu,topmenu)
.item:echo item
}
The second is to use groups, and decide which menu to show when either script is loaded:
#group1 on
menu @window {
topmenu
.item:echo item
}
#group1 end
on *:load:{
if ($showmenu) {
enable #group1
disable #group2
}
else {
disable #group1
enable #group2
}
}