web-dev-qa-db-ja.com

Googleを切り替えるChrome AppleScriptを使用してタブ

私は次のコードがその仕事をすることを望んでいましたが、葉巻はありません:

--Only the window is brought into focus
tell application "Google Chrome"
    activate tab 1 of window 1
end tell
5
Orion751

Google Chromeは、実際にはスクリプト可能です。

tell application "Google Chrome" to set active tab index of first window to 3

バージョン10.0.648.204のチャームのように機能します。


次のようなことをするといいのですが:

tell application "Google Chrome" to set active tab of first window 
    to first tab of the first window whose title is "Super User"

active tabは読み取り専用プロパティであるため、これは不可能です。すべてのウィンドウのタブをループして、各タブのタイトルを照会して目的のウィンドウのインデックスを見つけ、active tab indexを設定する必要があります。

tell application "Google Chrome"
    set i to 0
    repeat with t in (tabs of (first window whose index is 1))
        set i to i + 1
        if title of t is "Super User" then
            set (active tab index of (first window whose index is 1)) to i
        end if
    end repeat
end tell
10
Daniel Beck

この驚くべきスクリプトを完成させたところです。これには多くのグーグルと推測が必要でしたが、機能します。

tell application "Google Chrome"
    activate
    repeat with w in (windows)
        set j to 0
        repeat with t in (tabs of w)
            set j to j + 1
            if title of t contains "Workflowy" then
                set (active tab index of w) to j
                set index of w to 1
                tell application "System Events" to tell process "Google Chrome"
                    perform action "AXRaise" of window 1 -- `set index` doesn't always raise the window
                end tell
                return
            end if
        end repeat
    end repeat
end tell

do Shell script is from here :ウィンドウにキーストロークを受け入れさせます。

FastScripts を使用して、これを機能させることができます(他にも多くの方法があります)

4
Dan Rosenstark

Netflixを一時停止して再生するスクリプトを作成しようとしていましたが、上記のコードはタブを検索するための優れたフレームワークでした。 「whoseindexis 1」は、Mac Mini 10.8.3でコンパイラエラーをスローし続けたため、 http://en.blog.guylhem.net/post/9835498027/google-chrome-next-)のコードに基づいています。 tab-in-applescript 、参照を完全に削除しました(これは私の目的のために機能しました)

スクリプトは基本的にブラウザウィンドウをアクティブにし、「Netflix」というタイトルのタブが見つかるまでタブを通過し、キーコード49(スペースバー)を送信します。

tell application "Google Chrome"
    activate
    set i to 0
    repeat with t in (tabs of (first window))
        set i to i + 1
        if title of t is "Netflix" then
            set (active tab index of (first window)) to i
        end if
    end repeat
    tell application "System Events" to key code 49
end tell
1
user216409

Google Chromeはスクリプト化できません(つまり、Appleイベント)を理解しません)。AccessibilityAPI(これは[システム環境設定]> [システム]> [ユニバーサルアクセス]でオンにする必要があります。下部にある[補助デバイスのアクセスを有効にする]チェックボックスを参照してください。これは、 システムイベント のプロセススイートを介して行われます。残念ながら、これは一般的なケースでは非常に苦痛ですが、

tell application "System Events"
    tell application process "Google Chrome"
        click tab 1 of window 1
    end tell
end tell

十分かもしれません。そうでない場合は、ウィジェットツリーからタブ要素を明示的に掘り下げる必要があります。 Appleにはいくつかの サンプルコード があり、UI要素を見つけるのに役立ちます。

0
geekosaur