1

我正在寻找一种通过 url 关闭 safari 中特定选项卡的方法。我可能会扩展这样的内容:

tell application "Safari"
    repeat with t in tabs of windows
        tell t
            if name starts with "google.com" then close
        end tell
    end repeat
end tell

这里的问题是我还没有找到一种方法来获取选项卡的 url 值并基于此关闭它们。

4

2 回答 2

3

您可以根据活动选项卡从 Safari 获取 URL。

tell application "Safari"
    set w to first window
    set t to current tab of w
    display dialog (URL of t as string)
end tell

然后你可以像这样遍历每个标签/页面:

tell application "Safari"
    set windowCount to number of windows
        repeat with x from 1 to windowCount
            set tabCount to number of tabs in window x
            repeat with y from 1 to tabCount
                set thistab to tab y of window x
                set foo to URL of thistab
                if foo is not equal to "bar" then close thistab
           end repeat
       end repeat
end tell
于 2013-07-01T13:57:43.270 回答
1

这是另一种方法:

set closeURLs to {"http://www.yahoo.com", "http://www.apple.com"}

repeat with theURL in closeURLs
    tell application "Safari" to close (every tab of every window whose URL contains (contents of theURL))
end repeat
于 2013-07-01T14:05:42.560 回答