open dict://“$word” stopped working for Chinese after upgrading to Big Sur

Solution 1:

This seems to be a bug with the open command when handling certain characters—for instance, open http://www.google.com?q=中 gives a similar error message. It might be worth reporting this bug to Apple; in the meantime, you can use the following (admittedly less than elegant) workaround:

osascript -l JavaScript -e "(a = Application.currentApplication()).includeStandardAdditions=true; a.openLocation('dict://' + encodeURIComponent('中'))"

This uses JavaScript for Automation to encode and open the URL, just as open does. To use the generic $word format, you would just make the following substitution:

osascript -l JavaScript -e "(a = Application.currentApplication()).includeStandardAdditions=true; a.openLocation('dict://' + encodeURIComponent('$word'))"