1

trying to get the current string written in the search bar in Firefox to be copied to my clipboard, than translating it like it was written in Hebrew keyboard layout, than pasting the translated string, and then changing keyboard layout.

#!/bin/bash


declare -A engToHeb=(
[q]="/" [w]="'"
  [e]="ק" [r]="ר" [t]="א" [y]="ט" [u]="ו"
  [i]="ן" [o]="ם" [p]="פ"
  [a]="ש" [s]="ד" [d]="ג" [f]="כ" [g]="ע"
  [h]="י" [j]="ח" [k]="ל" [l]="ך" [;]="ף"
  [z]="ז" [x]="ס" [c]="ב"
  [v]="ה" [b]="נ" [n]="מ"
  [m]="צ"
  [,]="ת"
  [ ]=" "
)

declare -A hebToEng=(
  [/]="q" [\']="w" [ק]="e" [ר]="r" [א]="t" [ט]="y" [ו]="u"
  [ן]="i" [ם]="o" [פ]="p" [ש]="a" [ד]="s" [ג]="d" [כ]="f"
  [ע]="g" [י]="h" [ח]="j" [ל]="k" [ך]="l" [ף]=";"
  [ז]="z" [ס]="x" [ב]="c" [ה]="v" [נ]="b" [מ]="n" [צ]="m"
  [ ]=" "
)

xdotool keyup Shift+Super+Left key shift+Home
xdotool keyup Shift+Super+Left key ctrl+x
word=$(xclip -o -selection clipboard)

for ((i=0;i<${#word};i++))
do
my_char=${word:$i:1}
new_word+=${engToHeb[$my_char]}
new_word+=${hebToEng[$my_char]}
done

echo $new_word | xclip -selection clipboard

xdotool keyup Shift+Super+Left key ctrl+v
xdotool keyup Shift+Super+Left key alt+shift

alt shift is a bind for toggeling to hebrew/english

  • please include a sample word to test with and the expected output. Assuming the problem is with output, comment out reading the variable, and just have a basic assignment, `word=TestWord`. Also you might want to share with some minimal detail what you have tried and the results. Sorry I have no experrence with xdtool, but your bash code looks reasonable. Did you check it at https://shellcheck.net ? Good luck. – shellter Mar 10 '23 at 17:24
  • Also, I don't see why you would use both `engToHeb[]` and `hebToEng[]` in the same loop. you're alternating characters in your `new_word` result. Good luck. – shellter Mar 10 '23 at 20:53
  • translating the word working fine, the main effect I want this program to do is coping what ever I wrote with shift+home (when you shift+home in browser it will mark the line you just wrote) than I want to copy it, make the translation to the other keyboard layout(for ex if I wrote יקקךם than I want it to become hello), after the translation has been made I want it to paste the new translated word in the browser and toggle my keyboard layout to the other lang. – aviv levari Mar 11 '23 at 07:59
  • I"m not having much luck going thru the `xkb` documentation looking for ideas. I did find https://wiki.debian.org/DebianHebrew, but it has a to-do list, which includes `hebrew_kbd` which is now a dead link. It seems that the crux of your problem is toggling keyboard layouts. I will look for ideas as I have time. Do you have any inormation on working hebrew keyboard definitions? Good luck. – shellter Mar 11 '23 at 19:36

0 Answers0