Applescript在Safari中的标签之间切换

问题描述 投票:0回答:1

[尝试创建自动化以打开带有多个标签的Safari浏览器并登录到我每天使用的常见网站。我已经实现了打开浏览器并添加具有特定URL的新选项卡,并提示用户输入用户名和密码,但是在简单地在打开的选项卡之间移动时遇到了困难。我尝试分配索引,命名“当前选项卡”,使用标题等。似乎没有任何作用...请参见下面的示例...

--Prompt user for login information
set GEmail to text returned of (display dialog "Enter Password" with title "Gmail" default answer "")
set GPassword to text returned of (display dialog "Enter Password" with title "Gmail" default answer "")
--Activate Safari and open new tab with URL
tell application "Safari"
    activate
    make new document with properties {URL:"https://gmail.com"}
    delay 3
    tell application "System Events"
        delay 2
        keystroke tab
        keystroke GEmail
        delay 2
        keystroke tab
        keystroke GPassword
        keystroke return
        end tell
--Create new tab pointing to Google > this does not actually open the new tab
set the URL of (make new tab in window 1) to "http://www.google.com"
end tell

我已经尝试了多种方法,但似乎仍然无法在各个标签之间真正地移动,最终将需要添加更多我需要在其中切换的标签。

safari applescript
1个回答
0
投票

要创建新的tab,同时将焦点设置为给定的URL使用,例如:

tell application "Safari" to ¬
    tell front window to ¬
        set current tab to ¬
            (make new tab with properties {URL:"http://www.google.com"})
© www.soinside.com 2019 - 2024. All rights reserved.