以下是一个使用 AppleScript 在 Safari 中切换选项卡的示例代码:
tell application "Safari"
set currentTab to current tab of front window
set allTabs to tabs of front window
repeat with i from 1 to count of allTabs
if tab i of front window is currentTab then
set nextTabIndex to (i mod (count of allTabs)) + 1
set nextTab to tab nextTabIndex of front window
set current tab of front window to nextTab
exit repeat
end if
end repeat
end tell
这段代码将获取当前活动选项卡,并遍历所有选项卡,找到下一个选项卡的索引。然后,它将将下一个选项卡设置为当前选项卡,从而实现选项卡之间的切换。
要在 AppleScript 中运行此代码,请按以下步骤操作:
请注意,此代码仅适用于 Safari 浏览器。如果您希望在其他应用程序中切换选项卡,您需要相应地修改代码。