2016-08-19 60 views
0

我想找到的Safari标签,并注重这个标签的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

权短语带来了选项卡前景

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 

-

可以在后台标签执行的JavaScript。指定这样的标签:

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

谢谢你,那太棒了。第一个脚本(查找标签)工作正常,但始终有一个错误“Safari得到一个错误:无法获得每个窗口的项目2的每个选项卡。” –

+0

这可能是一个僵尸窗口。我已经更新了答案。 – user309603

+0

只是一件小事,你会如何将标签号保存为变量?我尝试了如果t的名称包含“谷歌”,然后将tabNumber设置为t,但结果看起来像“应用程序的每个窗口的项目1的每个选项卡的项目5”Safari“” –