open dict://“$word” stopped working for Chinese after upgrading to Big Sur Not sure if this question is appropriate for this forum. If not, please let me know, and I will remove it (if I can).
I have a shell script open dict://&quot;$word&quot; that worked well in Catalina for both English and Chinese. It will open the Dictionary.app and look up the word for me.
Problem:
After upgrading to Big Sur, it now works only for English, not for Chinese anymore. If I try to look up a Chinese word, say, to execute open dict://&quot;中&quot;, it will give an error in the Terminal.app: The file /Users/USERNAME/dict:/天 does not exist. Looking up an English word, say open dict://'hello', acts normally (i.e., it opens Dictionary.app and looks up &quot;Hello&quot; in the app). I can still look up Chinese words using Dictionary.app's interface.
I'm an amateur in programming. I don't know what I can try to solve this problem.
Any help appreciated! Thanks in advance!
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 &quot;(a = Application.currentApplication()).includeStandardAdditions=true; a.openLocation('dict://' + encodeURIComponent('中'))&quot;

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 &quot;(a = Application.currentApplication()).includeStandardAdditions=true; a.openLocation('dict://' + encodeURIComponent('$word'))&quot;