Last active
May 16, 2019 15:42
-
-
Save pavloo/db5eed391fe5a2ef0356bbae69ec273b to your computer and use it in GitHub Desktop.
A script to enable/disable certain keystrokes in BetterTouchTool when external keyboard connected/disconnected
This file contains 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
tell application "BetterTouchTool" | |
activate | |
update_trigger "EAE52DEC-26DA-40DC-8BB1-62A102FE676C" json "{\"BTTEnabled\" : %d}" | |
update_trigger "7C3BC3BC-2B93-4674-8A5F-6697FDC6E723" json "{\"BTTEnabled\" : %d}" | |
end tell |
This file contains 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
const usbDetect = require('usb-detection'); | |
const applescript = require('applescript'); | |
const util = require('util'); | |
const fs = require('fs'); | |
const path = require('path'); | |
usbDetect.startMonitoring(); | |
function runAppleScript(script) { | |
applescript.execString(script, (err, rtn) => { | |
if (err) { | |
console.error(err); | |
} | |
}); | |
} | |
const KEYBOARD_NAME = 'USB-HID Keyboard'; | |
const SCRIPT_FMT = fs.readFileSync(path.resolve(__dirname, 'btt-enable-disable.applescript.template'), 'utf-8'); | |
console.log(SCRIPT_FMT); | |
usbDetect.on('add', function(device) { | |
if (device.deviceName !== KEYBOARD_NAME) { | |
return; | |
} | |
runAppleScript(util.format(SCRIPT_FMT, 0, 0)) | |
}); | |
usbDetect.on('remove', function(device) { | |
if (device.deviceName !== KEYBOARD_NAME) { | |
return; | |
} | |
runAppleScript(util.format(SCRIPT_FMT, 1, 1)) | |
}); |
This file contains 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
{ | |
"name": "keyboard-switch", | |
"version": "1.0.0", | |
"description": "Simple module to switch BTT preset when external keyboard is attached/deattached", | |
"main": "index.js", | |
"author": "Pavlo Osadchyi", | |
"license": "MIT", | |
"private": null, | |
"dependencies": { | |
"applescript": "^1.0.0", | |
"usb-detection": "^4.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment