I do not have any applications launched by .xinitrc. I did more experimentation and I think I can now explain the basis for the odd behaviour. I believe it stems from the fact that
X11.app does not like DISPLAY to be set to :0.
Here are three similar scripts that react quite differently. It is assumed that the environment variable DISPLAY is not set prior to executing the scripts.
#! /bin/sh
DISPLAY=:0; export DISPLAY
xterm &
/usr/bin/osascript -e 'tell application "/Applications/Utilities/X11.app" to activate'
In this case no xterms end up being launched. Because DISPLAY set to :0, the xterm from the script and (presumably) the xterm in X11.app time out with an error "xterm Xt error: Can't open display: :0". After that X11 actually starts up and I can launch other applications normally. The applications inherit DISPLAY=:0.
2)
#! /bin/sh
xterm -display :0 &
/usr/bin/osascript -e 'tell application "/Applications/Utilities/X11.app" to activate'
In this case two xterms are launched. The script xterm probably just sits because of its display :0 flag, however, because the DISPLAY environment variable is not set, the following line launches
X11.app and its own xterm. Once X11 is running the initial xterm also launches and we end up with two xterms.
3)
#! /bin/sh
xterm &
/usr/bin/osascript -e 'tell application "/Applications/Utilities/X11.app" to activate'
This script follows the latest rules and indeed produces the desired result of launching one xterm. The xterm call goes through launchd/X11.app as expected. The following osascript brings
X11.app to the front otherwise, when the script is bundled, the xterm would launch behind the Finder window.
I believe this unusual behaviour could be circumvented if lauchd/X11.app would accept display settings of the form :0, localhost:0.
Cheers -John