The previous post describes the hoops I jumped through to enter Unicode characters on a Mac. Here’s a script to run from the command line that will copy Unicode characters to the system clipboard. It runs anywhere the Python module pyperclip
runs.
#!/usr/bin/env python3 import sys import pyperclip cp = sys.argv[1] ch = eval(f"chr(0x{cp})") print(ch) pyperclip.copy(ch)
I called this script U
so I could type
U 03c0
at the command line, for example, it would print π to the command line and also copy it to the clipboard.
Unlike the MacOS solution in the previous post, this works for any Unicode value, i.e. for code points above FFFF.
On my Linux box I had to install xclip
before pyperclip
would work.
The post Cross-platform way to enter Unicode characters first appeared on John D. Cook.