9

I have a problem with Autokey: I can't copy-paste through it a special Unicode character. Here is an example:

I am French, and in French writing, you use a space before a semi-colon. But in formal typography, you don't use a regular space before a semi-colon but a ‘narrow no-break space’ which is the Unicode character U+202F.

So when I am writing formal things in French, instead of always wasting time typing CTRL+Shift+U+202F+ENTER+;+space', I would like to use an Autokey new phrase. Using the abbreviation Space+;; (which means, verbally, typing space, then semi-colon twice). Which means when I type (anywhere) space+;;, autokey transforms it into  ; (which is a narrow no-break space followed by a semi-colon).

BUT the problem here is this: when I create a new phrase in Autokey with  ;, then when I use the abbreviation, Autokey replaces it only with ;, erasing the narrow no-break space. And it appears it does this with any other too-special Unicode character...

Does anyone have an idea of how to get round this issue?

Thanks a million!

Zanna
  • 70,465
yoannjap
  • 111

2 Answers2

6

Two options: (See my blog for more details and screenshots for option 1)

First option (much simpler)

Upgrade to the python 3 port of autokey (because python 3 deals with unicode characters better than python 2)

For me, the installation worked as follows:

# Edit (April 2018). Autokey now uses python 3 by default. So try
pip3 install autokey

# Install the original autokey
sudo apt-get install autokey-gtk
# Update autokey to python 3 using pip3  
pip3 install --user autokey-py3

Then make sure you run the python3 version, which is probably at

~/.local/bin/autokey-gtk

With this method, you can enter your unicode characters as phrases

Second option (if you can't get autokey-py3 to work)

Use a python script (File -> New -> Script) together with the system's clipboard

Paste the following into the script

import sys                                                                                                                                                              
reload(sys)                                                                                                                                                             
sys.setdefaultencoding('utf8')                                                                                                                                          
from subprocess import Popen, PIPE                                                                                                                                        

def paste_character(symbol):                                                                                                                                                   
    c = Popen(['xclip', '-selection', 'clipboard'], stdin=PIPE)                                                                                                           
    c.communicate(symbol.encode('utf-8'))                                                                                                                                 
    keyboard.send_keys('<ctrl>+v')

paste_character('γ')

This works by changing the default python settings to work with unicode correctly. It then sends the chosen character to the clipboard (ensure you have xclip installed). Here I've used γ as an example). Then it sends control+v to paste the character.

Extras for second option

The second method can be improved by taking all but the last line of the script and putting it in a file (lets call it MyCopy.py). Then, in Autokey's preferences (Script Engine), tell Autokey where this file is. Then the script becomes

from MyCopy import paste_character
paste_character('γ')

Some applications don't use control+v for paste (eg terminal uses control+shift+v). But the character will still be on the clipboard.

hugke729
  • 291
  • Any chance you could visit us over at the AutoKey list https://groups.google.com/forum/#!forum/autokey-users ? I am trying to get a very simple script to work in the modules directory and can't quite get it. BTW, I have posted a link to this question there as we often get questions related to Unicode issues. – Joe Sep 12 '16 at 03:35
0

Works for me in Linuxmint 19.3, which runs python 3.6.8.

BUT doesn't work for me in Linuxmint 20.0, either as python 3.6.8 or 3.8.5. Repeatedly get this script error:

Script name 'amacron'

Traceback (most recent call last);

File "/usr/lib/python3/dist-packages/autokey/service.py" 
line 485, in execute exec(script.code, scope)
File "", line 2, in 
NameError:name 'reload' is not defined

===

amacron script:

import sys
reload(sys)
sys.setdefaultencoding('utf8')

from subprocess import Popen, PIPE def paste_character(symbol): c = Popen(['xclip', '-selection', 'clipboard'], stdin=PIPE) c.communicate(symbol.encode('utf-8')) keyboard.send_keys('+v') paste_character('ā')

Harryg123
  • 341
  • 1
  • 4
  • 7