AppleScript:搜索safari选项卡并打开选项卡

时间:2016-08-19 11:10:36

标签: safari tabs applescript

我想找一个safari标签,并专注于此标签

这不起作用,但是找不到标签,我只是无法打开此标签。

tell application "Safari"
    repeat with t in tabs of windows
        tell t
            if name starts with "facebook" then open tab
        end tell
    end repeat
end tell

此外,我想我能否从另一个标签中找到一些文字,而不关注此标签?

to getInputByClass75(theClass, num)
    tell application "Safari"
        set input to do JavaScript "
document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" in document 1
    end tell
    return input
end getInputByClass75
getInputByClass75("Order", 0)
set theText to Unicode text
set theSource to getInputByClass75("Order", 0)

property leftEdge75 : "<a class=\"columns\" href=\"/Web"
property rightEdge75 : "\">Display</a>"
set saveTID to text item delimiters
set text item delimiters to leftEdge75
set classValue to text item 2 of theSource
set text item delimiters to rightEdge75
set OrderLink to text item 1 of classValue
set text item delimiters to saveTID
OrderLink

1 个答案:

答案 0 :(得分:1)

将标签置于前景的正确短语是

tell window x to set current tab to tab y

试试这个

tell application "Safari"
    repeat with w in windows
        if name of w is not "" then --in case of zombie windows
            repeat with t in tabs of w
                if name of t starts with "facebook" then
                    tell w to set current tab to t
                    set index of w to 1
                end if
            end repeat
        end if
    end repeat
end tell

-

您可以在后台标签中执行javascripts。像这样指定标签:

tell application "Safari"
    do JavaScript "document....." in tab 1 of window 1
end tell