2012-09-10 159 views
2

我需要編寫關閉FireFox中特定標題的選項卡。是否存在與下面的AppleScript示例相同的FireFox?使用AppleScript關閉FireFox中的特定選項卡

在Safari關閉標籤頁:

tell application "Safari" 
    delete (every tab of every window where its name contains "[done]") 
end tell 

關閉標籤頁的Chrome:

tell application "Google Chrome" 
    delete (every tab of every window where its title contains "[done]") 
end tell 

回答

5

因爲Firefox不會有任何AppleScript的支持,你需要依靠UI腳本。當然,Firefox的非標準用戶界面也無濟於事,但仍有可能。試試這個:

tell application "System Events" to tell process "firefox" 
    set frontmost to true 
    repeat with w from 1 to count of windows 
     perform action "AXRaise" of window w 
     set startTab to name of window 1 
     repeat 
      if name of window 1 contains "[done]" then 
       keystroke "w" using command down 
      else 
       keystroke "}" using command down 
      end if 
      delay 0.2 
      if name of window 1 is startTab then exit repeat 
     end repeat 
    end repeat 
end tell 
+0

謝謝,這真是幫了我。 – rein