Author Topic: strange scripting problem  (Read 1425 times)

0 Members and 1 Guest are viewing this topic.

Offline excalibur1234

  • Global Moderator
  • *****
  • Posts: 2508
  • Branch: unstable
  • Desktop: net-minimal + LXQt
  • GPU driver: video-nouveau
  • Kernel: 4.6
  • Skill: Intermediate
strange scripting problem
« on: 07. February 2016, 17:00:26 »
i try to run the command
Code: [Select]
xmodmap -e "clear Lock"
after every boot. this command will remove the Caps_Lock functionality from the caps lock key on my keyboard.


every time i open a terminal and execute the command
Code: [Select]
xmodmap -e "clear Lock"
my caps lock key stops working (as intended).


then, i created this script:
Code: [Select]
#!/bin/bash

xmodmap -e "clear Lock"
sleep 20 && xmodmap -e "clear Lock" && qterminal -e pacli
sleep 20 && exec xmodmap -e "clear Lock"
sleep 20 && qterminal -e xmodmap -e "clear Lock"
sleep 20 && exec qterminal -e xmodmap -e "clear Lock"
the script is executable and the "&& qterminal -e pacli" part acts as a check, whether the previous command has ended successfully.
i have set this script to autostart after every boot.


this script runs SUCCESSFULLY after every boot, at least the second line (otherwise, i would not see pacli in a qterminal window), but my caps lock key is still working.
i just cannot understand, why the "xmodmap -e "clear Lock"" command works, when i execute it manually but not when i run it in a script (which runs successfully).
why is manjaro acting so strange?
what am i doing wrong?
Need more information? Search here:   Manjaro Forum   |   Manjaro Wiki   |   Arch Wiki

Offline jonathon

  • Core Team
  • *****
  • Posts: 2104
  • Technologist - Teacher - Tea drinker
  • Branch: Unstable
  • Desktop: MATE 1.14
  • GPU Card: Nvidia GTX680M
  • GPU driver: Bumblebee nvidia+intel
  • Kernel: 4.6.0-*-MANJARO x86_64
  • Skill: Advanced
Re: strange scripting problem
« Reply #1 on: 07. February 2016, 17:22:10 »
Start by adding `set -e -x` after the shebang. -e will exit after an error, -x will report the command being run and its output. This should provide far better debugging than running a terminal.

What you should see is that nothing after the first `exec` is running. See more about `exec`: http://wiki.bash-hackers.org/commands/builtin/exec

Incidentally, the command `xmodmap -e 'clear Lock'` does nothing for me under MATE.
« Last Edit: 07. February 2016, 17:27:43 by jonathon »
--
MSI GT70: Core i7-3630QM, 16GB, Nvidia GTX680M, Intel 2230, Manjaro-MATE-amd64-EFI
Lenovo X230: Core i5-3320M, 4GB, Intel HD4000, Intel 6205, Manjaro-MATE-amd64
Dell Studio 1749: Core i5 540, 8GB, ATi HD5650, Intel WLAN, Manjaro-Xfce-amd64
Let's go in the garden; you'll find something waiting.

Offline excalibur1234

  • Global Moderator
  • *****
  • Posts: 2508
  • Branch: unstable
  • Desktop: net-minimal + LXQt
  • GPU driver: video-nouveau
  • Kernel: 4.6
  • Skill: Intermediate
Re: strange scripting problem
« Reply #2 on: 07. February 2016, 19:03:57 »
thanks for the tip.

i have rewritten my script:
Code: [Select]
#!/bin/bash
set -e -x

sleep 10 && xmodmap ~/.Xmodmap
xmodmap -e "clear Lock"
sleep 5 && xmodmap -e "clear Lock"

this is my terminal output, when i run it:
Code: [Select]
~ ยป ./.xmodmap_autostart
+ sleep 10
+ xmodmap /home/ex/.Xmodmap
+ xmodmap -e 'clear Lock'
+ sleep 5
+ xmodmap -e 'clear Lock'
so, i do not notice any problem. the script runs successfully and it does what it is supposed to do: my caps lock key on my keyboard stops working.


but when i reboot my computer and lxqt runs that script as part of the autostart, the first part of my script "xmodmap /home/ex/.Xmodmap" is run successfully (i.e. my keyboard layout changes), but the "xmodmap -e 'clear Lock'" command is obviously not doing what it is supposed to do: my caps lock key is still working.
« Last Edit: 07. February 2016, 19:07:57 by excalibur1234 »
Need more information? Search here:   Manjaro Forum   |   Manjaro Wiki   |   Arch Wiki

Offline Bertie

  • Neuling
  • *
  • Posts: 14
  • I'm old. Be nice!
  • Branch: Stable
  • Desktop: Net+E20 (+fvwm)
  • GPU Card: Intel HD5000
  • GPU driver: Free
  • Kernel: Linux44-x64
  • Skill: Novice
Re: strange scripting problem
« Reply #3 on: 07. February 2016, 22:24:02 »
The command ' xmodmap -e "clear Lock" ' also does nothing for me in Enlightenment.
Maybe it is LXQT specific.
Does your autostart script not run before LXQT is started, thus missing the meaning?

Offline excalibur1234

  • Global Moderator
  • *****
  • Posts: 2508
  • Branch: unstable
  • Desktop: net-minimal + LXQt
  • GPU driver: video-nouveau
  • Kernel: 4.6
  • Skill: Intermediate
Re: strange scripting problem
« Reply #4 on: 08. February 2016, 19:06:30 »
when you look at my script, you see this part:
Code: [Select]
sleep 10 && xmodmap ~/.Xmodmap
xmodmap -e "clear Lock"
this will run both commands "xmodmap ~/.Xmodmap" and "xmodmap -e "clear Lock"" almost at the same time. i am sure the first command does what it is supposed to do, because my keyboard layout gets changed. only the second command does not do what it is supposed to do (but the script does not give me any error). i already have tried to vary the time my script runs.
when i run the second command manually, it works well.

for this reason, i doubt that it timing has anything to do with it.


i am not 100% sure, but i think in order for "xmodmap -e "clear Lock"" to work properly, you first have to assign the caps lock function to another key. this is my .Xmodmap file:
Code: [Select]
keycode 66 = F13
keycode 133 = F14
clear Lock
keycode 21 = Caps_Lock
add Lock = Caps_Lock
first, it assigns F13 to my caps lock key.
then, it assigns F14 to my windows/meta/super key
then, it removes the lock modifier from the caps lock key.
then, it assigns caps lock to an unused key.
then, it assigns the caps lock modifier to the (new) unused key.

this script is not working as i intended it to work. when i run it, i have 2 keys with caps lock functionality: the new unused key and F13 (the old caps lock key). but when i run "xmodmap -e "clear Lock"" manually, it removes the caps lock modifier from F13 (which does not make sense, because it should remove the caps lock modifier from the unused key - which i assigned the caps lock modifier to).

i never really understood xmodmap. i think i have seriously tried to fix this specific problem about 5-6 times now. i have tried at least 50 different .Xmodmap files with all commands i thought were reasonable (in all possible orders of commands). in the end, i always think xmodmap is broken and i have to work around it.
Need more information? Search here:   Manjaro Forum   |   Manjaro Wiki   |   Arch Wiki

Offline Bertie

  • Neuling
  • *
  • Posts: 14
  • I'm old. Be nice!
  • Branch: Stable
  • Desktop: Net+E20 (+fvwm)
  • GPU Card: Intel HD5000
  • GPU driver: Free
  • Kernel: Linux44-x64
  • Skill: Novice
Re: strange scripting problem
« Reply #5 on: 08. February 2016, 22:39:31 »
Sorry, I assumed wrongly that you ran your script from xinitrc which would result it being run before LXQt has started. I only notice now that you did mention it being run as part of the LXQt autostart, thus after LXQt has started.

Even though ' xmodmap -e "clear Lock" ' does nothing for me, it also does not give an error.

Offline excalibur1234

  • Global Moderator
  • *****
  • Posts: 2508
  • Branch: unstable
  • Desktop: net-minimal + LXQt
  • GPU driver: video-nouveau
  • Kernel: 4.6
  • Skill: Intermediate
Re: strange scripting problem
« Reply #6 on: 09. February 2016, 19:12:24 »
thanks for your effort.
as i have described in my last post, the command works for me, but not in a way that i can understand WHY it works, because it works differently than i expected (and i have read often in other posts on the internet). maybe this command is just broken...
Need more information? Search here:   Manjaro Forum   |   Manjaro Wiki   |   Arch Wiki

Offline Lambda

  • Neuling
  • *
  • Posts: 12
  • Skill: Advanced
Re: strange scripting problem
« Reply #7 on: 14. April 2016, 17:47:17 »
u also can write in to ur .Xmodmap file under ur home directory.

Code: [Select]
remove Lock = Caps_Lock
This disable Caps_Lock.

for example, show ur my .Xmodmap file
Code: [Select]
pointer = 3 2 1 4 5 6 7

remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L

1st disable which key do u want no working.
2nd rebind a key to u want defined
3rd enable defined key again

then, add this

Code: [Select]
xmodmap ~/.Xmodmap
in ur .xinitrc file
« Last Edit: 14. April 2016, 17:53:27 by Lambda »

Offline Heart Of A Lion

  • Sr. Mitglied
  • ****
  • Posts: 313
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: Xfce, Enlightenment
  • GPU Card: ATi 7770 . . . . . . . CPU: AMD octacore 4GHz
  • GPU driver: Free (video-ATI)
  • Kernel: 4.6 (x64)
  • Skill: Intermediate
Re: strange scripting problem
« Reply #8 on: 14. April 2016, 18:03:04 »
Maybe with that line you are trying to access a part of the system that hasn't fully booted yet immeditely after startup.

Which is perhaps why it works when you type it in a terminal, but doesn't work right after startup.

I had to account for such things in my own startup scripts as well.


Try using a different interpreter for your script by changing the shebang line - to see if that makes any difference:

Code: [Select]
#!/bin/sh
« Last Edit: 14. April 2016, 18:37:07 by jonathon »

Offline excalibur1234

  • Global Moderator
  • *****
  • Posts: 2508
  • Branch: unstable
  • Desktop: net-minimal + LXQt
  • GPU driver: video-nouveau
  • Kernel: 4.6
  • Skill: Intermediate
Re: strange scripting problem
« Reply #9 on: 14. April 2016, 21:02:44 »
thanks for the tips.
i just did some some tests again:

- i used a couple of different versions of my autostart script:
Code: [Select]
#!/bin/sh
##!/bin/bash
sleep 10 && xmodmap ~/.Xmodmap
#sleep 30 && xmodmap ~/.Xmodmap
#xmodmap -e "clear Lock"

- i used different Xmodmap files:
Code: [Select]
remove Lock = Caps_Lock
clear Lock
keycode 66 = F13
keycode 133 = F14
keycode 21 = Caps_Lock
Code: [Select]
remove Lock = Caps_Lock
clear Lock
keycode 66 = F13
keycode 133 = F14
keycode 21 = Caps_Lock
add Lock = Caps_Lock
nothing has worked so far. my caps lock key (with keycode 66) still has 2 functions at the same time: as a caps lock key and as F13.
i simply do not what is going on. i think i understand the code in my Xmodmap file pretty well, but it works differently than i think it does.

i will keep testing...
Need more information? Search here:   Manjaro Forum   |   Manjaro Wiki   |   Arch Wiki

Offline oli

  • Vollwertiges Mitglied
  • ***
  • Posts: 123
  • Branch: stable
  • Desktop: Openbox, Pekwm
  • GPU Card: Intel core processor integrated graphics controller
  • GPU driver: Free
  • Kernel: 3.18 or 3.16
  • Skill: Novice
Re: strange scripting problem
« Reply #10 on: 19. April 2016, 17:14:19 »
I've had similar issues to this before... I forget exactly what, but it has happened several times. I can't remember what I have done to find solutions, I think I always found a way to hack around the issue without understanding exactly what was going on. One thing I remember once is some scripts refusing to run unless they were in my home directory which was odd, also maybe executing it via another script. I remember doing something like this once. Like run a script:

Code: [Select]
#stupid script 1
sleep 20s && sh ~/yourscript.sh
from your autostart file?? I know it sounds completely ridiculous but maybe worth a try?? Good luck and if you find anything about why its happening then would be interesting to know.
Didn't we already pass that same stack of rocks twice?

Offline excalibur1234

  • Global Moderator
  • *****
  • Posts: 2508
  • Branch: unstable
  • Desktop: net-minimal + LXQt
  • GPU driver: video-nouveau
  • Kernel: 4.6
  • Skill: Intermediate
Re: strange scripting problem
« Reply #11 on: 07. May 2016, 14:22:39 »
i finally found the solution to this problem by accident:
i had to choose a different keyboard layout.

until now, i have used the default "german (eliminate dead keys)". today i chose "german (dead grave acute)" and after a reboot my system starts with the working script!

i am puzzled why this solved my problem, but it could be the following:
i use the "dead acute" key on my keyboard as the new caps lock key, because i do not use that key and i still wanted a caps lock key. somehow the keyboard layout interfered with xmodmap.

Need more information? Search here:   Manjaro Forum   |   Manjaro Wiki   |   Arch Wiki