Created
May 30, 2025 16:10
-
-
Save xcud/a3587af9788837b4c89aafd96c28225a to your computer and use it in GitHub Desktop.
A bash script to quickly disable your laptop keyboard when your cat decides to sit on it while you're using an external keyboard. Make it executable: `chmod +x cat_mode.sh`, bind it to an F key, adjust keyboard ID (run xinput list to find yours)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Cat Mode Toggle Script | |
# Detects current state and toggles between enabled/disabled keyboard | |
KEYBOARD_ID=28 | |
MASTER_ID=3 | |
TIMER_PID_FILE="/tmp/keyboard_timer_pid" | |
# Function to check if keyboard is currently floating (disabled) | |
is_keyboard_disabled() { | |
# Check if keyboard is floating by looking at xinput list | |
xinput list | grep -q "id=$KEYBOARD_ID.*floating slave" | |
return $? | |
} | |
# Function to disable keyboard (activate cat mode) | |
disable_keyboard() { | |
# Disable the keyboard | |
xinput float $KEYBOARD_ID | |
# Show notification | |
notify-send "Cat Mode Activated" "Keyboard disabled for 30 minutes" -i input-keyboard | |
echo "Keyboard disabled. It will automatically re-enable in 30 minutes." | |
echo "To manually toggle back, press F8 again or run this script." | |
# Schedule automatic re-enable in 30 minutes (1800 seconds) | |
(sleep 1800 && xinput reattach $KEYBOARD_ID $MASTER_ID && notify-send "Cat Mode Deactivated" "Keyboard automatically re-enabled" -i input-keyboard && rm -f $TIMER_PID_FILE) & | |
# Store the background job PID | |
echo $! > $TIMER_PID_FILE | |
echo "Timer PID: $! (saved to $TIMER_PID_FILE)" | |
} | |
# Function to enable keyboard (deactivate cat mode) | |
enable_keyboard() { | |
# Re-enable the keyboard | |
xinput reattach $KEYBOARD_ID $MASTER_ID | |
# Kill the timer if it's still running | |
if [ -f $TIMER_PID_FILE ]; then | |
PID=$(cat $TIMER_PID_FILE) | |
if kill -0 $PID 2>/dev/null; then | |
kill $PID | |
notify-send "Cat Mode Deactivated" "Timer cancelled, keyboard re-enabled" -i input-keyboard | |
else | |
notify-send "Cat Mode Deactivated" "Keyboard manually re-enabled" -i input-keyboard | |
fi | |
rm -f $TIMER_PID_FILE | |
else | |
notify-send "Cat Mode Deactivated" "Keyboard manually re-enabled" -i input-keyboard | |
fi | |
echo "Keyboard manually re-enabled" | |
} | |
# Main logic: detect current state and toggle | |
if is_keyboard_disabled; then | |
echo "Cat mode is currently ACTIVE. Disabling cat mode..." | |
enable_keyboard | |
else | |
echo "Cat mode is currently INACTIVE. Activating cat mode..." | |
disable_keyboard | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment