使用AppleScript

时间:2016-10-27 06:38:01

标签: safari applescript

我正在使用苹果脚本重新加载所有的safari选项卡,我想忽略重新加载的一个打开的选项卡。下面是我重新加载已打开标签的代码。

  tell application "Safari"
         repeat
            repeat with i from (count of tabs of window 1) to 1 by -1
               set thisTab to tab i of window 1
               set current tab of window 1 to thisTab
               tell application "System Events"
                    keystroke "r" using {command down}
               end tell
               delay 10
             end repeat
         end repeat
    end tell

1 个答案:

答案 0 :(得分:0)

您可以按索引过滤(重新加载除标签4之外的所有内容)

tell application "Safari"
    repeat
        repeat with i from (count of tabs of window 1) to 1 by -1
            if i is not 4 then
                set thisTab to tab i of window 1
                set current tab of window 1 to thisTab
                tell application "System Events"
                    keystroke "r" using {command down}
                end tell
                delay 10
            end if
        end repeat
    end repeat
end tell

或通过URL(重新加载其URL不包含“myServer”的每个选项卡)

tell application "Safari"
    repeat
        repeat with i from (count of tabs of window 1) to 1 by -1
            set thisTab to tab i of window 1
            if URL of thisTab does not contain "myServer" then
                set current tab of window 1 to thisTab
                tell application "System Events"
                    keystroke "r" using {command down}
                end tell
                delay 10
            end if
        end repeat
    end repeat
end tell