Applescript在后台运行Safari



我有一个appdescription,它现在正在做我想做的事情:打开一个特定的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

有人能解决这个问题吗?

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

相关内容

最新更新