Applescript不会让Safari在新窗口中打开URL

时间:2016-08-31 16:28:06

标签: applescript

我正在制作收到所选文字的Applescript服务,并使用此文字打开Goog​​le查询。这是它的第一个版本:

on run {input, parameters}
set myBrowser to http://google.com.br?q=" & input as text
set the_url to "Safari" as text

tell application myBrowser
    open location "http://google.com.br?q=" & input
    set the bounds of the front window to {100, 22, 800, 1024}
    activate
end tell
end run

上面这个很好用。当我尝试使浏览器打开包含查询的新页面而不是新选项卡时出现问题。我不得不想出一个解决方案,因为它不会在新窗口打开两个标签,因为它会在触发脚本并关闭Safari时发生:

on run {input, parameters}
set the_url to "http://google.com.br?q=" & input
set myBrowser to "Safari" as text

set aWindowIsOpen to false
tell application myBrowser
    repeat with thisWindow in windows
        if (not miniaturized of thisWindow) then
            set aWindowIsOpen to true
        end if
    end repeat

    if (aWindowIsOpen) then
        make new document with properties {URL:the_url}
        set the bounds of the front window to {100, 22, 800, 1024}
        activate
    else
        activate
        make new document with properties {URL:the_url}
        set the bounds of the front window to {100, 22, 800, 1024}
        activate
    end if
end tell
end run

现在问题是浏览器不会打开URL。有没有?

1 个答案:

答案 0 :(得分:1)

Use tell application "Safari" instead of tell application myBrowser.


Or, use using terms from application "Safari", like this:

set myBrowser to "Safari"
using terms from application "Safari"
  tell application myBrowser
      make new document with properties {URL:the_url}
  end tell
end using terms from