Created
November 29, 2024 10:46
-
-
Save Strajk/42eb7b2c643d0b8bdf4bbd63dfda77b2 to your computer and use it in GitHub Desktop.
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
// Name: Karabiner Elements Profile Switcher | |
// Acknowledgements: | |
// - https://www.alfredforum.com/topic/9927-karabiner-elements-profile-switcher/ | |
// Notes: | |
// - Probably could also work with cli https://github.com/raycast/extensions/blob/be03024b4c4f4f1ad0af7f4d20ea4630d7f0ee20/extensions/karabiner-profile-switcher/src/model/KarabinerManager.ts | |
import "@johnlindquist/kit" | |
import fs from 'fs' | |
const CONFIG_PATH = home('.config/karabiner/karabiner.json') | |
const configJson = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')) | |
const profileChoices = configJson.profiles.map((profile: any) => ({ | |
name: profile.name, | |
value: profile.name, | |
tag: profile.selected ? '🟢' : '', // Note: Not sure if there's a better way to highlight currenly active | |
})) | |
const selectedProfile = await arg({ | |
placeholder: 'Select a profile', | |
choices: profileChoices, | |
}) | |
for (const profile of configJson.profiles) { | |
profile.selected = profile.name === selectedProfile // intentional mutation | |
} | |
fs.writeFileSync(CONFIG_PATH, JSON.stringify(configJson, null, 2)) | |
notify(`Karabiner Elements profile switched to "${selectedProfile}"`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment