关闭Safari选项卡

时间:2013-06-04 21:29:55

标签: tabs safari applescript

我搜索了包括这里关闭标签的方法。 我有这个代码应该工作:

tell application "Safari"
    repeat with aWindow in windows
        repeat with aTab in tabs of aWindow
            if name of aTab is "Facebook" then
                tell aTab to close
            end if
        end repeat
    end repeat
end tell

我打开了一个Facebook标签但它不起作用,代码似乎在关闭整个窗口时起作用了......

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试:

tell application "Safari" to close (every tab of every window whose name = "Facebook")

您需要在代码的重复循环中包含内容。

tell application "Safari"
    repeat with aWindow in windows
        repeat with aTab in tabs of (contents of aWindow)
            set aTab to contents of aTab
            if name of aTab is "Facebook" then
                tell aTab to close
            end if
        end repeat
    end repeat
end tell