首页 文章

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

提问于
浏览
1

我正在制作一个Applescript服务,接收所选文本并使用此文本打开Google查询 . 这是它的第一个版本:

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 回答

  • 1

    使用 tell application "Safari" 而不是 tell application myBrowser .


    或者,使用 using terms from application "Safari" ,如下所示:

    将myBrowser设置为“Safari”
    使用应用程序“Safari”中的术语
    告诉应用程序myBrowser
    制作包含属性的新文档{URL:the_url}
    结束告诉
    结束使用来自

相关问题