Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: How do I change a custom keyboard shortcut from the command line?

  1. #1
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,336
    Distro
    Ubuntu

    Question How do I change a custom keyboard shortcut from the command line?

    In Ubuntu, I can go to Settings > Keyboard > View and Customise Shortcuts > Custom Shortcuts. There, I can add, delete or change custom keyboard shortcuts.

    What I'd like to know is how to do this on the command line (so that I can use it in a script)? I know BASH, but no other language.

    I've searched online for the solution but found nothing.

    Thank you
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  2. #2
    Join Date
    Mar 2007
    Location
    Promiseland
    Beans
    1,683
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: How do I change a custom keyboard shortcut from the command line?

    Hello Paddy,

    Have you considered an alias defined in .bash_aliases to implement your desired shortcut?
    Cheers,


    The Linux Command Line at https://linuxcommand.org/

  3. #3
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,336
    Distro
    Ubuntu

    Re: How do I change a custom keyboard shortcut from the command line?

    Quote Originally Posted by him610 View Post
    Have you considered an alias defined in .bash_aliases to implement your desired shortcut?
    Thanks, but keyboard shortcuts are for the GUI, not for the terminal. It's those keyboard shortcuts that I wish to change, but using a script instead of using the GUI.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  4. #4
    Join Date
    Mar 2011
    Location
    U.K.
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: How do I change a custom keyboard shortcut from the command line?

    Would it be acceptable to have a UI automation script to flash through this process via Settings in a blink of an eye?

  5. #5
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,336
    Distro
    Ubuntu

    Re: How do I change a custom keyboard shortcut from the command line?

    Quote Originally Posted by dragonfly41 View Post
    Would it be acceptable to have a UI automation script to flash through this process via Settings in a blink of an eye?
    Um… Sorry, I don't understand what you're saying?

    To clarify with an example:

    Suppose that I have a keyboard shortcut Super+F11 to open VirtualBox. Now, I want Super+F11 to open GIMP instead. I can manually make this change by going to Settings > Keyboard > View and Customise Shortcuts > Custom Shortcuts, and making the change there. But, what I really want is a script to do make that change. In other words, how can I change the shortcut using a CLI command?
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  6. #6
    Join Date
    Mar 2011
    Location
    U.K.
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: How do I change a custom keyboard shortcut from the command line?

    I was attempting to suggest that you can "drive" established processes using commands ..
    Settings > Keyboard > View and Customise Shortcuts > Custom Shortcuts, and making the change there. But, what I really want is a script to do make that change.


    That is leverage proven tools to automate such actions. I know that CLI is the holy grail but if there are UI tools around I use them to speed up proven workflows rather than replacing them with Bash scripts.

    I will give one example. Install Albert, ensure it is in tool bar, then hit Ctrl+Space (I don't know why but it is required twice on my desktop). You are presented with a popup query field and that can be your sole portal into the Ubuntu galaxy rather than the usual launch terminal and run bash script. Just saying ...

  7. #7
    Join Date
    Dec 2014
    Beans
    2,695

    Re: How do I change a custom keyboard shortcut from the command line?

    I can't really speak about main-line Ubuntu and Gnome, but in XUbuntu / XFCE keyboard shortcuts are stored in xfconf and can be viewed and changed with xfconf-query.
    Code:
    xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/'<Primary><Alt>e' -n -s xeyes -t string
    This assigns Ctrl-Alt-e to starting xeyes. XFCE monitors xfconf and reacts to changes made to it's properties. I'd think that there's something similar in Gnome, probably gsettings.

    Holger

  8. #8
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,336
    Distro
    Ubuntu

    Re: How do I change a custom keyboard shortcut from the command line?

    Quote Originally Posted by Holger_Gehrke View Post
    probably gsettings
    Thank you — you might be onto something here. I'll have to search to find out how to specify key bindings with gsettings. (I don't have xfconf, nor is it in the standard repositories. It's obviously only for XFCE and LXDE.)
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  9. #9
    Join Date
    Mar 2011
    Location
    U.K.
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: How do I change a custom keyboard shortcut from the command line?


  10. #10
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,336
    Distro
    Ubuntu

    Re: How do I change a custom keyboard shortcut from the command line?

    Quote Originally Posted by dragonfly41 View Post
    Thanks for the link. Gnome Tweaks is a GUI. The answer given is about changing keys at a hardware level, which is not what I'm after.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •