2

I want to show the short discription of my current keyboard layout.

Currently it shows

Layout English (US)

or

Layout German

I would prefer EN(US) and DE.

I use the script from kbdd_layout. I could not figure out how the string is parsed and it would be great if someone would help me out.

Consider the code

#!/usr/bin/env bash
#    

killall kbdd 2>/dev/null
kbdd >/dev/null || exit 1

# Get initial state of layout
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
    /ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
    sed -un 's/^.*uint32 //p' )

# In case dbus service wasn't available yet, poll until service is ready
while [[ -z "$N" ]]; do
    sleep .1
    N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
        /ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
        sed -un 's/^.*uint32 //p' )
done
echo $( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
    /ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:$N )

# Parse dbus output
dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" |\
sed -un '0~2p' | sed -un 's:.*string "\(.*\)".*:\1:p' | sed -u '/:/d'

1 Answer 1

1

I did like follows (modified for your needs):

#!/usr/bin/env bash
# 

killall kbdd 2>/dev/null
kbdd >/dev/null || exit 1

# Get initial state of layout
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
    /ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
    sed -un 's/^.*uint32 //p' )

# In case dbus service wasn't available yet, poll until service is ready
while [[ -z "$N" ]]; do
    sleep .1
    N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
        /ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
        sed -un 's/^.*uint32 //p' )
done

dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
  /ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:$N |\
  sed -un 's:.*English.*:EN(US):p;s:.*German.*:DE:p'

# Parse dbus output 
dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" |\
  sed -un 's:.*English.*:EN(US):p;s:.*German.*:DE:p'

Just remember to tweak the script accordingly, in case if you will change layouts.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .