【发布时间】:2020-02-24 15:24:04
【问题描述】:
尝试创建自动化以打开具有多个选项卡的 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
我尝试了多种方法,但似乎仍然无法在选项卡之间移动,最终需要添加更多选项卡,我需要在这些选项卡之间切换。
【问题讨论】:
-
您能否更具体地说明您希望如何在选项卡之间移动?如果您的意思是用键盘循环浏览它们,那么它是 command-shift-} 使右侧的选项卡成为当前选项卡。如果您想在创建新选项卡的同时使其成为当前选项卡,那么打开位置“stackoverflow.com”是一种方法。我不完全理解你想要达到的目标。另外,Safari没有密码管理吗?不确定您使用的是什么版本。它可能比使用 applescript 更安全(但这是我的猜测)。
标签: safari applescript