tl;dr
を使用すると、ウィンドウが実際にアクティブ化されset index of window <n> to 1
ないという点で完全には効果的ではありませんが、ウィンドウが表示されます。
回避策(例では、ウィンドウ 2 をアクティブにすることを想定しています):
Yar の回答は実用的な回避策を提供しますが、それが機能する理由は完全には明らかではありません。ただし、次のソリューションとは異なり、呼び出し元のアプリケーションが補助アクセスを許可されている必要がないという利点があります。
user495470 の回答は、AppleScriptable 以外のアプリケーションでも機能する堅牢で汎用的なソリューションを示唆しています。
tell application "System Events" to tell process "Google Chrome"
perform action "AXRaise" of window 2
set frontmost to true
end tell
または、以下で定義されている AppleScript ハンドラを次のように使用します。
tell application "Google Chrome" to my activateWin(it, window 2)
adayzdoneの答えは機能 するはずであり、ほとんど機能しますが、問題がある場合とそうでない場合があります(Mountain LionのChrome 21.0.1180.89で観察されます)[更新:OSX 10.11.2のChrome 47.0.2526.106の時点でも適用されます] :
ソリューションは目的のウィンドウを前面ウィンドウとして表示しますが、別のウィンドウが以前にアクティブだった場合、Chrome はそれを前面ウィンドウとして扱いません。非アクティブな閉じる/分/ズームのタイトル バー ボタン、チェックマークが横にあるウィンドウ タイトル、および などのキーボード ショートカットCmd-L
が目的のウィンドウに適用されないという事実によってわかります。
次のアクションがとにかくウィンドウのどこかをクリックすることである場合、これは問題ではないかもしれません。そのようなクリックは目的のウィンドウを完全にアクティブにするからです。
それ以外の場合は、かなり堅牢な GUI スクリプトの回避策を採用できます (こちらの一般的なソリューションからありがたいことに適応しています)。
更新:悲しいことに、インデックスを1に設定したウィンドウを実際にアクティブにしないという問題は、すべてのアプリに影響を与えるようです(OS X 10.8.3で経験)。GUI スクリプトを使用して、特定の AppleScriptable アプリで特定のウィンドウを適切にアクティブ化する一般的な関数を次に示します。
# Activates the specified window (w) of the specified AppleScriptable
# application (a).
# Note that both parameters must be *objects*.
# Example: Activate the window that is currently the 2nd window in Chrome:
# tell application "Google Chrome"
# my activateWin(it, window 2)
# end tell
on activateWin(a, w)
tell application "System Events"
click menu item (name of w) of menu 1 of menu bar item -2 ¬
of menu bar 1 of process (name of a)
end tell
activate a
end activateWin
補足として、OP が試みたこと - たとえばactivate window 1
- OS X 10.8.3 のすべてのアプリでも同様に壊れているようです - 基礎となるアプリケーションがアクティブ化されている間、ウィンドウ仕様。は無視されます。
元の、より教訓的なコードは次のとおりです。
tell application "Google Chrome"
# Each window is represented by the title of its active tab
# in the "Window" menu.
# We use GUI scripting to select the matching "Window" menu item
# and thereby properly activate the window of interest.
# NOTE: Should there be another window with the exact same title,
# the wrong window could be activated.
set winOfInterest to window 2 # example
set winTitle to name of winOfInterest
tell application "System Events"
# Note that we must target the *process* here.
tell process "Google Chrome"
# The app's menu bar.
tell menu bar 1
# To avoid localization issues,
# we target the "Window" menu by position - the next-to-last
# rather than by name.
click menu item winTitle of menu 1 of menu bar item -2
end tell
end tell
end tell
# Finally, activate the app.
activate
end tell