This is probably just me not knowing what I am doing, but I created a macro group titled "Mail Macros," and set the group so it's "Available in these applications:" --> "Mail."
My goal was to set the delete key as a hotkey for the key combination Ctrl + Cmd + A, which is the keyboard shortcut for 'archive message,' and to set that so it would only be active when Mail's main window is open — in oder to avoid interfering with message composition. (I compose messages in a separate window.) I didn't get as far as figuring out how to make the macro only available in Mail's primary window, because I first encountered what appears to be a bug: the macro is available in all applications as long as Mail is open.
Am I doing something wrong?
To kill two birds with one post: once the 'only available in Mail' issue is resolved, how do I limit the macro to Mail's primary window only?
Your macro configuration looks ok. Available in these applications will limit it to only when Mail is at the front.
My guess is something else is confusing you. First, try quitting and relaunch Keyboard Maestro editor to verify that the settings are actually sticking (and there is not some sort of permission or corruption issue).
Similarly, try quitting and relaunching the Keyboard Maestro Engine to verify that it is seeing the correct version of the macro group.
Neither of these are likely, but they rule out rare cases, and your macro configuration looks ok, so it's worth checking.
Then try the Interactive Help (in the Help menu) and verify that it actually is this macro triggering, and not some other copy of it or some other macro.
That is controlled by the next popup menu, Available in all windows, which lets you specify when the macro group is active based on the title of the front window.