open location not working when googling clipboard

Hi

I try to use this script:

set theURL to "http://google.com/search?q=" & (the clipboard as Unicode text)
open location theURL

(initiated manually but eventually through iKey)

Alas, it fails to work nor even give a proper error message when I run it while the clipboard contains non-ascii characters, or even punctuation marks. Firefox/Google handle all these as-is quite well.

How would I adjust the script to fire up the open location in any case?

Thanks!
Guy

Does this work any better for you?

open location "http://google.com/search?q=" & encodeURL(the clipboard)

on encodeURL(someText)
	return do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(unicode(sys.argv[1], \"utf8\"))' " & quoted form of someText
end encodeURL

Hi Bruce,

Your script indeed works for spaces in the string, but yields an error for non-ascii (Hebrew in my case) text in the clipboard.

http://bp3.blogger.com/_AI4kH2noLrg/Ry33IcE37iI/AAAAAAAAAEs/XWpc_dCv_4k/s1600-h/pastedGraphic-720818.png

Any ideas?

This eventually seemed to solve the problem:

open location "http://google.com/search?q=" & encodeURL(the clipboard)

on encodeURL(someText)
	return do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of someText
end encodeURL