Keymapping Variable for Bash Script?
Is there a variable which will tell you which keyboard mapping you are using?
I want to write a bash script that will change my keymapping from Dvorak keyboard to US keyboard. I cannot seem to find a variable to read from. I was going to use the "if [ ] then; statement". Anybody have any ideas? |
No, there's no variable for that. Keyboard mappings are a lot of data (mapping symbols to scancodes, basically, so they are large tables).
There are different mechanisms on the console and in X. In X, the command "xmodmap -pk" will print the keyboard mapping currently in use, but that is most definitely NOT what you want. So, I think you should explain what you want to do (what's the problem you are trying to solve by writing this script)? One thing I do not understand is why you need to know the current keymap in order to set a new one? |
zirias, I would like to make a script that changes the keymapping.
just want to create a test like this: if [ $KBD = dvorak ] then |
zirias, I would like to make a script that changes the keymapping.
just want to create a test like this: Code:
if [ $KBD = dvorak ] |
If you are in X11, you can try parsing output of "setxkbmap -print"
|
getting there...
good advice...
This is what I have so far. Code:
#!/bin/bash Code:
keyboard.sh: line 6: [: missing `]' |
revision...
I changed it to this:
Code:
#!/bin/bash Code:
(nothing) |
next step
then I ran this command:
Code:
bash -x keyboard.sh Code:
+ US=pc+us |
Well, you have simply a shell scripting problem.
[ = ] compares two its arguments in the shell sense. Now let us see what gets passed in your examples. Code:
[ setxkbmap -print | grep xkb_s | awk '{print $4}' = $US ] Code:
[ "setxkbmap -print | grep xkb_s | awk '{print $4}'" = "$US" ] What is a way that can work? You want to get the value of command execution. There is "$()" construct for that. Code:
echo "$(setxkbmap -print | grep xkb_s | awk '{print $4}')" Code:
[ "setxkbmap -print | grep xkb_s | awk '{print $4}'" = "pc+us" ] |
Quote:
Also the grep is kind of redundant if you're piping to awk anyway. Code:
[ "$(setxkbmap -print | awk '/xkb_s/{print $4}')" = $US ] |
Oops, yes, my fault - didn't read the first post in the chain attentively enough.
By the way, cryingthug, "+" in the beginning of the line just means that Bash debugger prints the executed command in this line. |
Thanks!
Raskin, Ntubski you guys are amazing! I thanked the both of you. This is the forum to come to. I'm learning more and more everyday.
|
[solved]
Hi!, this is what I ended up doing.
Code:
#!/bin/bash |
All times are GMT -5. The time now is 01:49 AM. |