2016-08-19 22 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「」 –