Automatically change keyboard layout

Forum / NoMachine for Linux / Automatically change keyboard layout

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10349
    quicksilver03
    Participant

    Hello,

    I’m using NX 5.1.7 to connect from a CentOS 7.2 laptop with a French keyboard to a CentOS 7.2 server with an Italian keyboard attached to it. Since I’m the only one connecting to this server, I would like to get the French keyboard layout for the duration of the NX session.

    I have modified /usr/NX/etc/node.cfg to configure 2 user scripts to automatically change the keyboard layout as such:

    
    UserScriptAfterSessionStart "/etc/NX/scripts/sessionstart.sh"
    UserScriptAfterSessionDisconnect "/etc/NX/scripts/sessionend.sh"
    UserScriptAfterSessionClose "/etc/NX/scripts/sessionend.sh"
    UserScriptAfterSessionFailure "/etc/NX/scripts/sessionend.sh"
    

    where the scripts are

    sessionstart.sh

    
    #!/bin/sh
    setxkbmap fr
    exit 0
    

    sessionend.sh

    
    #!/bin/sh
    setxkbmap it
    exit 0
    

    However, when I log in I still get the Italian keyboard layout: my script is either not called or if it’s called then it doesn’t affect my NX session.

    Any suggestion to make this work?

    Thanks in advance

    #10357
    Britgirl
    Keymaster

    Looking at the script, there’s an error.

    #!/bin/sh
    setxkbmap fr
    exit 0

     

    It should look like:
    #!/bin/sh
    XAUTHORITY=/home/$2/.Xauthority /usr/bin/setxkbmap fr -display :0

     

    setxkmbap needs to know which display has to be used and where the cookie is available, so every custom script you prepare with setxkbmap will require XAUTHORITY and -display.

    It might be a good idea to also enable the error logs from scripts and setxkbmap just in case:

    Add this to the beginning of the scripts ‘exec >> /usr/NX/var/log/custom.log 2>&1’

    #10386
    quicksilver03
    Participant

    Thank you so much for your help, with your additions the 2 scripts work perfectly and I get the keyboard layouts I need!

Viewing 3 posts - 1 through 3 (of 3 total)

This topic was marked as solved, you can't post.