How to include Mate custom keybinding in application package?

Hello,
I am packaging an application for visually impaired and I would like to have a keybinding packaged with that as well, so that the app can be easily launched. Any idea how to do that?
I thought I would package a gsettings override, something like

```
[org/mate/desktop/keybindings/custom0]
action='lios'
binding='<Alt><Mod4>l'
name='Linux Intelligent OCR Software'
```

But what if there is already "custom0" keybinding defined?

Thank you.
1 Like

IMHO, to solve the task correctly, an installation package must include a script to verify possible keybindings conflicts, to preserve already existing customizations, etc.

Then you need to create "custom1" or edit "custom0", rather than replace it.
It looks like the following link might be of interest

3 Likes

Hi, @hamster and welcome to the Ubuntu MATE Community!

Approach: Dynamic Keybinding Management

  1. Check Existing Keybindings: Before adding your keybinding, query the system's existing keybindings to ensure you don’t overwrite user-defined ones.
  2. Find an Available Slot: If custom0 is occupied, you can iterate through custom1, custom2, etc., until you find a free slot.
  3. Set the Keybinding: Use the gsettings command or a script to create the keybinding. sample Bash script to dynamically assign your keybinding:#!/bin/bash

APP_NAME="Linux Intelligent OCR Software"
APP_ACTION="lios"
APP_BINDING="l"

Check existing keybindings

SCHEMA="org.mate.desktop.keybindings"
BASE_PATH="/org/mate/desktop/keybindings/"
CUSTOM_KEYBINDING=""

for i in {0..99}; do
KEYBIND="custom$i"
ACTION=$(gsettings get $SCHEMA.$KEYBIND action 2>/dev/null)

# If the slot is empty, use it
if [[ "$ACTION" == "@as []" ]] || [[ "$ACTION" == "''" ]]; then
    CUSTOM_KEYBINDING=$KEYBIND
    break
fi

done

Exit if no available slot found

if [[ -z $CUSTOM_KEYBINDING ]]; then
echo "No available keybinding slots found."
exit 1
fi

Set the keybinding

gsettings set $SCHEMA.$CUSTOM_KEYBINDING name "'$APP_NAME'"
gsettings set $SCHEMA.$CUSTOM_KEYBINDING action "'$APP_ACTION'"
gsettings set $SCHEMA.$CUSTOM_KEYBINDING binding "'$APP_BINDING'"

echo "Keybinding set to $CUSTOM_KEYBINDING with binding $APP_BINDING" Explanation

  1. Check for Available Slots:
  • The script iterates over potential keybinding slots (custom0, custom1, ...).
  • It uses gsettings get to see if a slot is already assigned an action.
  • If it finds an empty slot, it stops iterating and uses that slot.
  1. Set the Keybinding:
  • The name, action, and keybinding are assigned using gsettings set.
  1. Fallback:
  • If no free slot is found (unlikely for small apps), the script exits with a message. let me furher Bz-NeV2.... Considerations

  • Desktop Environment Compatibility:

    • This example uses MATE (org.mate.desktop.keybindings). If your app targets GNOME or another desktop, adapt the schema accordingly (e.g., org.gnome.settings-daemon.plugins.media-keys for GNOME).
  • Permission:

    • Ensure the script runs with proper permissions. Some systems may require sudo to modify global settings.
  • Customization:

    • Allow users to configure the keybinding in case the default conflicts with their existing setup.

Packaging

Include this script in your application package and run it as part of the installation process or first-time setup. Alternatively, document it as a setup step for users who want the keybinding.

3 Likes

Hi, @neels_blizzard and welcome to the Ubuntu MATE Community!

Thanks....What a great Welcome..

1 Like