A popup menu causes an error if you try to post it while another application is in the foreground.
test code:
menu .pm
.pm add command -label test
bind . <Button-2> "tk_popup .pm %X %Y"
works fine if Wish is in the foreground.
If you click on any other application, then right-click on the Wish window (while leaving it in the background) an error is thrown on the .pm post command.
Looking at the implementation in tkMacOSXMenu.c, it appears that the popup menu requires a window reference that can only be obtained via [NSApp keyWindow]--c.f. a window with focus. I don't see another way to do it in Tk.
But arguably we ought to be more graceful about this failure case. Even if it can't work, it shouldn't throw an error in the user's face. Suggest trapping (just) this particular error in [tk_popup]…
That's a sensible suggestion--I'll take a look at implementing this.