AppleScript -> Activate window of a non-scriptable application

不打扰是莪最后的温柔 提交于 2019-12-12 09:04:30

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/3655502/applescript-activate-window-of-a-non-scriptable-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!