views:

67

answers:

1

Hi all, I have opened 2 "Finder" window A & B, A is in the front while B underneath, the following snippet brings B to the front the topmost:

tell application "Finder"
    activate
    activate window 2
end tell

But for applications that do not support scripting, the code just mentioned won't help.

Any ideas for activating a window of non-scripting application. Any help will be appreciate.

A: 

You can usually turn to system events in these cases. System events knows about the windows of running processes and you can usually manipulate those windows. Something like this will show you some of the things you can do. Just play around with the code and see if you can do what you want.

tell application "System Events"
    tell process "Whatever"
        properties of windows
    end tell
end tell

EDIT: One of the properties of a window is its "title". So you might be able to use that. This approach uses the fact that many applications have a "Window" menu and under that menu many times the name of the windows are listed and you can switch windows by clicking the approprite menu item. So something like this might work... my example uses TextEdit.

tell application "TextEdit" to activate
tell application "System Events"
    tell process "TextEdit"
        set windowTitle to title of window 2
        click menu item windowTitle of menu 1 of menu bar item "Window" of menu bar 1
    end tell
end tell
regulus6633
Thanks regulus6633, but I see no difference of the results while running your code for "Finder" and another application respectively.
I added another method to my post. Maybe it will help.
regulus6633
Excited, your approach does work, at least to my app! Thanks a lot!
Great. I'm glad you found a solution.
regulus6633