我正在尝试制作一个可以为您搜索谷歌的脚本,但是如果我进行多字搜索,则无效。任何人都知道如何解决这个问题?
set keyword to text returned of (display dialog "Enter Search Query" default answer "")
display dialog "Enter Search Query" buttons {"Cancel", "Ok"} default button 2
if the button returned of the result is "Ok" then
open location "http://search.yahoo.com/search?p=" & keyword
end if
答案 0 :(得分:0)
您只需要考虑空间并将其转换为“%20”
set aSpace to "%20"
display dialog "Enter Search Query" default answer "" buttons {"Cancel", "Ok"} default button 2
copy the result as list to {text_returned, button_pressed}
set t to words of text_returned
if the button_pressed is "Ok" then
open location "http://search.yahoo.com/search?p=" & encode(text_returned, space, aSpace)
end if
on encode(x, y, z)
tid(y)
set x to text items of x
tid(z)
return x as string
end encode
on tid(x)
set AppleScript's text item delimiters to x
end tid
编码代码来自here
答案 1 :(得分:0)
您还必须转义%和&等特殊字符。 open location
不适用于包含某些非ASCII字符的网址:
open location "http://ja.wikipedia.org/wiki/漢字"
do shell script "open http://ja.wikipedia.org/wiki/$(ruby -rcgi -e 'print CGI.escape(ARGV[0])' " & quoted form of "字%'\\&" & ")"
答案 2 :(得分:0)
如果只有一个对话框,则会打开两个对话框:
set myDialog to display dialog "Enter Search Query" default answer "" buttons {"Cancel", "Ok"} default button 2
set keyword to text returned of myDialog
if the button returned of myDialog is "Ok" then open location "http://search.yahoo.com/search?p=" & keyword
我不明白你的意思多次搜索没有工作。 对我来说,如果你在对话框中输入多个由空格分隔的单词,它就可以正常工作。