【问题标题】:Applescript won't make Safari open a URL at a new windowApplescript 不会让 Safari 在新窗口中打开 URL
【发布时间】:2016-09-01 02:33:14
【问题描述】:

我正在制作一个 Applescript 服务,它接收选定的文本并使用该文本打开一个谷歌查询。这是它的第一个版本:

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。有什么想法吗?

【问题讨论】:

    标签: applescript


    【解决方案1】:

    使用tell application "Safari" 代替tell application myBrowser


    或者,使用using terms from application "Safari",像这样:

    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
    

    【讨论】:

    • 太棒了,非常感谢!我只是在make命令之后添加了“激活”命令,否则窗口不会弹出到其他人面前。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    相关资源
    最近更新 更多