Reputation: 71
In my search for a solution to disable the keyboard on my Macbook, I am currently struggling with Launchd.
Some background first: I spilled some water on my Macbook Pro 2010 model and since then some keys on the keyboard no longer work. I started using the Mac as a desktop with external keyboard, mouse and monitor and went great for a while. But then it got worse with the shift-key getting stuck (not the key itself but somewhere on the motherboard I guess). The shift forces the Mac to boot into Safe Mode. I got around this by pressing the Option key during boot. But now there's something new: some keys are triggered randomly so the computer gets unusable... I got around this problem using a no-password login, and by running this shell command:
sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
I put this command in a script called disable-keyboard.sh. It works great! The internal keyboard is switched off, and the external keyboard works nice.
However, running this command is a real pain with the random triggered keys making it difficult to load a terminal. So I need to run this command at boot time. I got into Launchd:
I made a property list file:
more /Users/<username>/Library/LaunchAgents/DisableKeyboard.plist
<xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>DisableKeyboard</string>
<key>Program</key>
<string>/Users/<username>/disable-keyboard.sh</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
And it seems to work:
launchctl load /Users/<username>/Library/LaunchAgents/DisableKeyboard.plist
returns
Users/<username>/Library/LaunchAgents/DisableKeyboard.plist: service already loaded
However:
launchctl start DisableKeyboard
gives this error message in
system.log:
com.apple.xpc.launchd[1] (DisableKeyboard[292]): Program specified by service is not a Mach-O executable file.
What is wrong?
Upvotes: 3
Views: 2990
Reputation: 71
The correct script at /Users/<username>/disable-keyboard.sh
is:
#!/bin/bash
sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
Upvotes: 4