Skip to content

Instantly share code, notes, and snippets.

@atdt
Created July 1, 2015 20:43
Show Gist options
  • Save atdt/d634d00be9679ee0394e to your computer and use it in GitHub Desktop.
Save atdt/d634d00be9679ee0394e to your computer and use it in GitHub Desktop.
Temporarily disable MBP's internal keyboard, so I can clean it :)
#!/usr/bin/env bash
KEYBOARD_KEXT="/System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/"
countdown() {
local seconds="$1"
while [ $seconds -gt 0 ]; do
sleep 1 &
echo -n "${seconds}.. "
seconds=$(( $seconds - 1 ))
wait
done
echo
}
disable_keyboard() {
sudo kextunload "$KEYBOARD_KEXT" &>/dev/null
echo "Keyboard disabled."
}
enable_keyboard() {
sudo kextload "$KEYBOARD_KEXT" &>/dev/null
echo "Keyboard enabled."
}
# Get/extend sudo up-front for 5 minutes so it doesn't
# expire between the first and second command.
sudo -v
trap enable_keyboard EXIT
disable_keyboard
countdown 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment