Okay. Here's how I worked around the problem.
This keeps focus on the front mail-viewer-window when opening the Activity window, so my Keyboard Maestro macros perform the correct actions. It closes the Activity window if it's open already.
--------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/25 01:15
# dMod: 2015/10/25 01:30
# Appl: Mail, System Events
# Task: Toggle the Activity Window Open/Closed and bring focus back to the front Mail-Viewer.
# Tags: @Applescript, @Script, @Mail, @System_Events, @Toggle, @Activity, @Window, @Open, @Closed
# Note: Tested only on 10.11.1 with Mail in Classic-View.
--------------------------------------------------------------------------------------
try
tell application "System Events"
tell application process "Mail"
set frontmost to true
if (name of windows) does not contain "Activity" then
tell menu "Window" of menu bar item "Window" of menu bar 1
click menu item "Activity"
click menu item "Message Viewer"
end tell
else
tell window 1
tell attribute "AXCloseButton"
click its value
end tell
end tell
end if
end tell
end tell
on error e number n
stdErr(e, n, true, true) of me
end try
--------------------------------------------------------------------------------------