1

我有一个applescript,它现在正在做我想做的事情:打开一个特定的URL,关闭页面并等待2秒然后再做一次。该脚本有效。

问题是当我在我的机器上运行它时,我正在尝试同时做其他事情,Safari 窗口不断弹出。我真的很想在后台运行它,这样我就可以继续做我正在做的事情。

我的代码是:

set theURL to "https://sites.google.com/site/whatever/"

repeat 100 times
    tell application "Safari"
        activate
        try
            tell window 1 to set current tab to make new tab --with properties {URL:theURL}
            set URL of document 1 to theURL
        on error
            open location theURL
        end try
        delay 2
        try
            close window 1
        end try
    end tell

    tell application "Safari"
        quit
    end tell

    delay 1
end repeat

有人对此有解决方案吗?

4

1 回答 1

3

Safari 将出现在最前面,因为您在循环中激活它。

repeat 100 times
    tell application "Safari"
        if not (exists document 1) then reopen
        set URL of document 1 to "https://sites.google.com/site/whatever/"
        delay 2
        close window 1
        quit
    end tell
    delay 1
end repeat

编辑

set myURLs to {"https://www.google.com/", "http://www.yahoo.com/"}

repeat with aUrl in myURLs
    repeat 100 times
        tell application "Safari"
            if not (exists document 1) then reopen
            set URL of document 1 to aUrl
            delay 2
            close window 1
            quit
        end tell
        delay 1
    end repeat
end repeat
于 2013-08-12T15:59:28.893 回答