首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Applescript不会让Safari在新窗口打开URL

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

Stack Overflow用户
提问于 2016-08-31 16:28:05
回答 1查看 1.8K关注 0票数 2

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

代码语言:javascript
运行
复制
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时会发生这样的情况:

代码语言:javascript
运行
复制
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。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-31 18:33:14

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

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

将myBrowser设置为"Safari“,使用来自应用程序的术语"Safari”告诉应用程序myBrowser使用

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39254681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档