I was about to declare victory on this after making the modifications from posts #7 and #8 on this thread, but this issue just flared up again.
I have seen the issue occur in both Xcode and Google Chrome in the past. Currently however, it is happening in Chrome but NOT in Xcode. I'm not sure if that tells us anything new about the issue.
I reviewed your thread where you talked about Terminal.app's behavior where it switches focus back to the original window, and I think you are on to something there. Here's some additional testing I did:
1. I brought the affected program to the foreground, used shortcuts to show Alfred, and then hit escape. Note that I have "Show Alfred On... Active Screen" enabled.
1a. For the currently affected program (Google Chrome), it always returned focus to the Chrome window on my Thunderbolt display (which is selected as the primary window in System Prefs), no matter which Chrome window was highlighted prior to invoking Alfred.
1b. For unaffected programs, the system focus was correctly restored to the same in-focus window as before invoking Alfred.
2. I also tried switching to a different program besides Alfred (using CMD-TAB), and then switching back to the original program.
2a. For the currently affected program, the behavior was the same as when switching to/from Alfred. It always made the window on my Thunderbolt the in-focus window.
2b. For unaffected programs, the focus was sent to a window on the same display as the in-focus window on the previous app. Note that this is not the same behavior as when invoking Alfred and hitting escape.
@Andrew:
3. My findings in 2b were unexpected to me, but I assume this is why you recommended I enable "Show Alfred On... Active Screen"?
4. I'm starting to buy that this bug is not an issue with Alfred, but it's still troubling that there seems to be no way around it (according to your post on the Terminal.app thread). Especially since the system Paste command still functions as expected. I'm not familiar with the Apple APIs you have access to for developing Alfred, but I have a few followup questions/ideas:
4a. When pasting from Clipboard history, do you currently find the last active program, find the in-focus window for that program, find out where the cursor is in that window, and then paste in the text manually?
4b. Is there any way for you to query/detect where the system Paste command will be sent, and use that same location?
4c. Assuming something like 4a is true, is there any way to feed text directly into the system Paste command when invoking a paste from clipboard history, rather than inserting the text in the field manually?
Thanks again for taking the time to investigate this issue!