Guide to Creating a Custom Linux Keyboard Shortcut
A simple guide for creating custom keyboard shortcuts on Linux, focusing on the common GNOME Desktop Environment (used by Ubuntu) and using a specific Obsidian command as an example.
Guide to Creating a Custom Linux Keyboard Shortcut
Creating a system-wide keyboard shortcut involves two primary steps: defining the action to be executed and then mapping the desired key combination to that action within the system settings.
Part 1: Define the Command Action
For complex commands (like those using URL schemes or multiple chained actions), wrapping the command in a simple shell script is the most reliable method.
1. Create the Shell Script
A dedicated script ensures the command executes correctly, even if it contains characters or syntax that the shortcut utility might misinterpret.
- Location: A standard location for custom scripts is
~/bin/(thebinfolder in the user’s home directory). Create ashfile, e.g.,open-ob-vault.sh. - Command Example : The goal is to open a specific Obsidian vault using command
- Script Content:Note: The ampersand (
#!/bin/bash obsidian --vault "vault-name" &&) runs the command in the background, preventing the shortcut system from freezing while waiting for the application to launch.
2. Make the Script Executable
The file must have executable permissions for the system to run it.
- Terminal Command:
chmod +x ~/bin/open-ob-vault.sh
Part 2: Map the Action in System Settings (GNOME)
The second step is to configure the operating system to link the executable script to a key combination.
1. Navigate to Keyboard Settings
The location is typically found within the system configuration tools.
- Open the Settings application.
- Select Keyboard from the sidebar.
- Locate and select View and Customize Shortcuts (or similar wording, depending on the distribution version).
2. Create the New Custom Shortcut
This is where the script’s path is linked to a name and a key combination.
- Scroll down and select Custom Shortcuts.
- Click the + button (or Add Shortcut).
- A window will appear with three fields:
- Name: A descriptive name for the shortcut (e.g.,
Open Obsidian Daily). - Command: The full, absolute path to the script created in Part 1.
- Example Command:
/home/username/bin/open-ob-vault.sh(The user must substitute their actual username).
- Example Command:
- Shortcut: Leave this field blank for now and click the Add button.
- Name: A descriptive name for the shortcut (e.g.,
3. Set the Key Combination
After creation, the shortcut appears in the list but is usually marked as disabled.
- Click on the newly created shortcut’s row (the one marked “Disabled”).
- A dialog prompts for the new combination. Hold down the desired key combination (e.g., $Ctrl+Shift+O$).
- The system records the key combination.
The custom shortcut is now active and will execute the script when the assigned keys are pressed. The script will, in turn, open the specified Obsidian vault.