Skip to content

Instantly share code, notes, and snippets.

@christiandeange
Last active December 3, 2016 02:02
Show Gist options
  • Select an option

  • Save christiandeange/b75d4d9e7791b7222b73 to your computer and use it in GitHub Desktop.

Select an option

Save christiandeange/b75d4d9e7791b7222b73 to your computer and use it in GitHub Desktop.
Full-width character converter for OS X
#!/usr/bin/env python
import subprocess
import sys
DIFF = 0xFF01 - 0x0021
def transform(c):
i = ord(c)
if i >= 0x21 and i <= 0xFE:
return unichr(DIFF + i)
elif i == ord(' '):
return unichr(0x3000)
else:
return unichr(i)
if len(sys.argv) > 1:
input = ' '.join(sys.argv[1:])
else:
input = sys.stdin.readlines()
output = ''.join(map(transform, input)).encode('utf-8')
print output
subprocess.Popen(['pbcopy', 'w'], stdin=subprocess.PIPE, close_fds=True).communicate(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment