I've been trying to get any given window from another Application to become front most and focused.
Here are the two methods I have tried:
AppleScript
tell application "Safari"
set index of window "Downloads" to 1
activate
end tell
Why it doesn't work: While it seems to change the z-Order, it doesn't change the focus! The previous frontmost window, even if obfuscated, retains focus.
CoreGraphicServices
CGSWindowOrder(cid, wid, kCGSOrderAbove, nil)
Why it doesn't work: Without being the Universal Owner, you can't change the order of a window owned by another process. In this case, making myself the Universal Owner is not an option -- I don't want to depose the Dock.
Recap
I need to make a window frontmost and focused from one process to another. AppleScript fails to focus, and CGS isn't an option since I don't own the window.
Any solutions/ideas?