hbrown0579

Keyboard Switcher

Aug 13th, 2015
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. ###Example Script for Changing Keyboard Layout for Specific Application in Focus
  2.  
  3. from subprocess import PIPE, Popen
  4. from time import sleep
  5. from os import system
  6.  
  7. title = ''
  8. root_check = ''
  9.  
  10. while True:
  11.     sleep(0.6)
  12.     root = Popen(['xprop', '-root'],  stdout=PIPE)
  13.  
  14.     if root.stdout != root_check:
  15.         root_check = root.stdout
  16.  
  17.         for i in root.stdout:
  18.             if '_NET_ACTIVE_WINDOW(WINDOW):' in i:
  19.                 id_ = i.split()[4]
  20.                 id_w = Popen(['xprop', '-id', id_], stdout=PIPE)
  21.  
  22.         for j in id_w.stdout:
  23.             if 'WM_ICON_NAME(STRING)' in j:
  24.                 if title != j.split()[2]:
  25.                     title = j.split()[2]
  26.                    
  27.     if title = "Google Chrome":
  28.         system('gsettings set org.gnome.desktop.input-sources current 0')
  29.     if title = "Geogebra":
  30.         system('gsettings set org.gnome.desktop.input-sources current 1')
  31.  
  32.  
  33. ###The numbers in each line correspond to the indexed keyboard number in your input-sources list in Gnome settings.
Advertisement
Add Comment
Please, Sign In to add comment