Replacing Autokey in Wayland

Many Linux distros are leaving xorg (x11) for Wayland, as display server protocol. Unfortunately not all the applications are ready for Wayland.

In particular Autokey, a very useful application to expand text and automatize typing operations, is not (yet) compatible with Wayland.

A quite good replacement of Autokey is Espanso. But there are also some limitations:

  • Espanso has big problems in LibreWriter (abbreviations are often expanded with errors). Similar problems there were also with Autokey in LibreWriter, but Autokey was able to provide some workarounds.
  • Espanso, unlike Autokey, can provide a very small range of hotkeys (such as ctrl + alt + d): Espanso can use only hotkeys with ctrl (not with alt or shift) and a few letters. I.g. “x01” means “ctrl + a”. You can find the whole range of possible combinations here.

However, as long as the main typing operations are in LibreWriter, or Kate, you can use that applications possibilities to expand text.

in LibreWriter there are at least two possibilities (to expand an abbreviation):

  • tools – > autocorrect
  • tools -> autotext

In Kate you can use snippets to create something similar to Autokey.

I.g. to create a snippet to wrap selected text with the tag <h1>, you can add this code as snippet code:

${rangeCommand("<h1>%%1</h1>", "title")}

Choose the title as you prefer (obviously without spaces), and a key combination, i.g. ctrl+1.

Don’t forget to add, in the javascript section (the tab scripts) this code

function rangeCommand(command, def) {
    if (view.selectedText().length > 0) {
        return command.replace("%%1", view.selectedText());
    } else {
        return command.replace("%%1", def);
    }
}

In this way, you will be able to add a title <h1> to your selected text.

libreoffice 7 and autokey

To avoid a deal of errors with autokey (QT) in LibreOffice 7 (and KDE 5.20) it could be necessary install the KDE Frameworks 5 integration.
Here, at least, it worked.

problems with “locale”

In case of problems with locale (i.g. autokey not starting, or a file with non-latin characters not opening) you can try these commands

  • export LC_ALL=”en_US.UTF-8″
  • export LC_CTYPE=”en_US.UTF-8
  • sudo dpkg-reconfigure locales

python script per cycle case (lower – mixed – upper)

Utile con autokey. Eccolo:

pre.CICodeFormatter{
font-family:arial;
font-size:12px;
border:1px dashed #CCCCCC;
width:99%;
height:auto;
overflow:auto;
background:#f0f0f0;
line-height:20px;
background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);
padding:0px;
color:#000000;
text-align:left;
}
pre.CICodeFormatter code{
color:#000000;
word-wrap:normal;
}

 # Get the current selection.  
 sText=clipboard.get_selection()  
 lLength=len(sText)  
   
 try:  
   if not store.has_key("textCycle"):  
     store.set_value("state","title")  
   
 except:  
   pass  
   
 # get saved value of textCycle  
 state = store.get_value("textCycle")  
   
   
 # modify text and set next modfication style  
 if state == "title":  
   #sText=sText.capitalize()  
   sText=sText.title()  
   newstate = "lower"  
   
 elif state == "lower":  
   sText=sText.lower()  
   newstate = "upper"  
   
 elif state == "upper":  
   sText=sText.upper()  
   newstate = "title"  
   
 else:  
   newstate = "lower"  
   
 # save for next run of script  
 store.set_value("textCycle",newstate)    
   
 # Send the result.  
 keyboard.send_keys(sText)  
 keyboard.send_keys("<shift>+<left>"*lLength)  

exclude a program from autokey

Per settare più programmi con autokey, in window filter
(progr1)|(progr2).

per escludere un programma da un item di autokey 

Si può usare questa regex: ^((?!.*Firefox).)*$
In questo caso escludiamo Firefox: non occorre mettere tutto il nome della window, ma solo la parte finale (senza spazi o punti). In effetti la finestra di Firefox sarebbe “Navigator.Firefox”, ma così non funzionerebbe.

un bug 

L’esclusione suddetta non funziona per il terminale (konsole). Speriamo che risolvano. Per aggirare questo ostacolo si possono indicare (positivamente) tutti gli altri programmi in cui si usa quella abbreviazione.

libreoffice autokey bug

C’è un bug in LibreOffice (e anche in OpenOffice): non funziona autokey, se non in modo inaccettabilmente pasticciato. Non cambia la musica cambiando autokey-gtk con autokey-qt.
Bug anche nella funzione di autocorrezione di LibreOffice: fa dei gran casini con abbreviazioni come “ig” per “in generale” e simili.
Che guaio.
D’altronde OnlyOffice, che pare abbia una compatibilità del 100% con MS Office è un programmino commerciale-commerciale, tutto superficie: niente bookmarks, limitatissime possibilità di macro (solo js) e impossibilità di richiamarle personalizzando tastiera e menu (non sono personalizzabili). Va bene negli uffici per documenti usa e getta, non per uno che deve scrivere per riviste scientifiche o per libri.

Workaround: usare la funzione di autocorrezione di LO disabilitando temporaneamente autokey (shift+meta+k). Così si ottiene la sostituzione delle abbreviazioni con il testo da noi scelto. Ad esempio “ip” diventa “in particolare” senza pasticci.