Applescript won';不要让Safari在新窗口打开URL
我正在制作一个Applescript服务,它接收选定的文本并用该文本打开一个google查询。这是它的第一个版本:Applescript won';不要让Safari在新窗口打开URL,applescript,Applescript,我正在制作一个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="
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。有什么想法吗?使用
告诉应用程序“Safari”
而不是告诉应用程序myBrowser
或者,使用应用程序“Safari”中的术语,如下所示:
太棒了,非常感谢!我只是在make命令之后添加了“activate”命令,如果不是这样,窗口就不会在其他人面前弹出。
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