0

I use a usb keyboard with my laptop. It has a layout that's different from the builtin, so I have script to switch between them. But if I forget to switch before unplugging, I have no super. Now I'm in a different room, and I can't be bothered to get my keyboard. I can't get to a terminal in this x session without super, but I can switch to a different console. But if I try to execute the script there, it says cannot open display 'default display'. Can I run it for the open x session from the console?

PS: the script:

#!/bin/bash
killall xcape
if lsusb | grep HHKB ; then {
        setxkbmap us,gr \
                -variant carpalx-plus-intl,daedalus \
                -option grp:win_space_toggle \
                -option lv3:rwin_switch \
                -option altwin:meta_alt \
                -option shift:breaks_caps \
                -option lv5:lsgt_switch_lock
        xmodmap ~/.xmodmap/hh
        xcape -e "Shift_L=F13;Shift_R=F13;Super_L=Prior;Hyper_L=Prior"
} &
else {
        setxkbmap us,gr \
                -variant carpalx-plus-intl,daedalus \
                -option grp:win_space_toggle \
                -option lv3:ralt_switch \
                -option altwin:meta_alt \
                -option shift:breaks_caps -option lv5:lsgt_switch_lock
        xmodmap ~/.xmodmap/apple
        xcape -e "Control_L=Escape;Shift_L=F13;Shift_R=F13;Alt_L=Escape;Alt_R=Escape"
} &
fi
0

You need to set your DISPLAY variable before running the script.

Try:

DISPLAY=:0  yourscriptname
  • Didn't work. If logged in as same user, there was no output. If logged in as root, it said cannot open display ":0" // no protocol specified. – Toothrot Feb 12 '17 at 12:51
  • You can test the X connection to see if DISPLAY is working using something like "DISPLAY=:0 xdpyinfo" which should print display info – Chunko Feb 12 '17 at 12:56
  • Perhaps the script to change the input device is not working after the USB device was unplugged? Maybe it only works when it is plugged in. Can you post the script that modifies the super key. Maybe it's not done in a reversible operation way? – Chunko Feb 12 '17 at 12:59
  • 1
    A good thing to try is save your environment from a terminal in your proper session using env > file.text then in your tty you can try loading that before running your command. – Chunko Feb 12 '17 at 13:08
  • 1
    To load the saved env, in your shell, use "source file.text" but I don't think it will be much help now – Chunko Feb 12 '17 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.