2013-04-07 34 views
0

我想做一個腳本,將爲您做一個谷歌搜索,但如果我做了多個詞搜索,它不起作用。有人知道怎麼修這個東西嗎?Applescript:打開位置與多個詞不工作

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

你只需要佔空間,並將其轉換/他們爲「%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

+0

當我運行它時,它表示它預計「在編碼和tid上」中的「on」是其他 – 2013-04-08 18:08:46

+0

嗨,這沒有什麼意義。你能發佈完整的錯誤嗎?這個腳本在這裏工作正常。沒有錯誤。你有沒有改變我發佈的腳本。如果是這樣如何? – markhunte 2013-04-08 20:42:05

+0

沒關係。我所要做的只是指定一個瀏覽器。謝謝! '將關鍵字設置爲返回的文本(顯示對話框「輸入搜索查詢」默認答案「」) 顯示對話框「輸入搜索查詢」按鈕{「取消」,「確定」}默認按鈕2 如果返回結果的按鈕是「好的」,然後 打開位置「http://search.yahoo.com/search?p=」和關鍵字 end if' – 2013-04-08 22:15:00

0

您還可以逃避特殊字符,如%和&。而open location不會有一些非ASCII字符的URL工作:

open location "http://ja.wikipedia.org/wiki/漢字" 

可以url encode using a shell雖然:

do shell script "open http://ja.wikipedia.org/wiki/$(ruby -rcgi -e 'print CGI.escape(ARGV[0])' " & quoted form of "字%'\\&" & ")"

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 

我不明白你的意思與你多個搜索沒有工作。 對我而言,如果在對話框中輸入多個由空格分隔的單詞,則工作得很好。