Ändern Sie die URL eines Tabs mit einem Apple-Skript

Ich versuche, die URL des Chrome-Tabs mit Apple Script festzulegen. Ich verwende diesen Code. Die URL-Zeichenfolge wird erfolgreich festgelegt, aber um die URL zu ändern, muss die Eingabetaste gedrückt werden. Dieser letzte Schritt macht meinen Code funktionsunfähig, da er die aktuelle Website, die ich besuche, nicht ändert. Welche Problemumgehung empfehlen Sie? Chrome ist bereits geöffnet.

tell application "Google Chrome"

    tell application "System Events"
        tell application process "Google Chrome"
            set value of text field 1 of toolbar 1 of window 1 to "http://www.url.com/"

        end tell
    end tell
end tell

Antworten (1)

Eine Möglichkeit, dies mit dem integrierten Skripting von Chrome zu tun:

tell application "Google Chrome" to set URL of active tab of window 1 to "http://example.com"

Und um Ihr Skript zu erweitern, um die Eingabetaste zu drücken:

tell application "Google Chrome"
    tell application "System Events"
        tell application process "Google Chrome"
            set (text field 1 of toolbar 1 of window 1)'s focused to true
            set value of text field 1 of toolbar 1 of window 1 to "http://example.com/"
            keystroke return
        end tell
    end tell
end tell
Vielleicht liegt es an meinem System, aber Ihr erweitertes Skript wird nicht kompiliert. Es schlägt fehl Syntax Error Expected “,” but found number.und hebt hervor, 1nachdem toolbarich Version 49.0.2623.108 (64-Bit) von Google Chrome ausgeführt habe. Ich vermute jedoch, dass dies daran liegen könnte, dass ich OS X 10.8.5 ausführe und insbesondere AppleScript 2.2.4 nicht unterstützt diese Syntax.