Open URL: URL Including Chinese Characters Failed

Hi,
Does anyone know how to properly set the url that includes Chinese characters with the Open URL action?

Test URL:

https://www.youtube.com/results?search_query=编程

I tried this below but it failed:

I also tried the Percent Encode for URL before it and it still failed.

Thanks!

1 Like

Hi @martin,
Using this action
KM 0 2021-09-07_22-59-20
loads the desired web page into the clipboard. I was then able to paste into an HTML editor to actually see the web page.

I don't know if that's helpful to you or not, that's your call!

Thanks. But that's not what I wanted. I want to open the url in a web browser.

Hey @peternlewis,

I was able to percent-encode the Chinese characters and get the URL to work via AppleScript:

open location "https://www.youtube.com/results?search_query=%E7%BC%96%E7%A8%8B"

But the same URL is still rejected by Keyboard Maestro...

-Chris

1 Like

Did you turn off token processing? Seems to work fine for me.

image

image

2 Likes

Yes, I know. That’s why I said

1 Like

The simplest solution here might be not to percent encode the whole URL (that also encodes the colon and slashes and other characters the URL needs to function, which is why the macro fails when you try that) but only the search query, and to use that as a variable in conjunction with a predefined URL:

Example Macro.kmmacros (1.6 KB)

4 Likes

Hey Friends,

Thanks a lot for helping out. This is very helpful!

Both @peternlewis and @gglick have provided the solution. I'm gonna mark @gglick's post as solution since it is more nuanced.

The wiki page is very brief. I hope it can be updated regarding this issue.

@peternlewis, is it possible to add native Chinese character (probably other languages as well) support in the action so that it will work with urls such as https://www.youtube.com/results?search_query=编程? It is more intuitive.

It is interesting to note that different browsers also handle this differently.

Microsoft Edge, Safari, and Firefox show:

image

But Vivaldi shows:

image

1 Like

Hmm. I was sure I had tried that last night, but I just tried again – and it worked...

1 Like

The URL has to be a valid URL, as defined by the NSURL and the URL specification.

Native characters are not valid in a URL, regardless of browsers being permissive and allowing their use.

2 Likes