Skip to content

Instantly share code, notes, and snippets.

@humblehacker
Created January 14, 2024 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humblehacker/06151a3c9b2bd4029b0236c322aacc78 to your computer and use it in GitHub Desktop.
Save humblehacker/06151a3c9b2bd4029b0236c322aacc78 to your computer and use it in GitHub Desktop.
Choose next Karabiner profile
#!/usr/bin/env zsh
alias kb="/Library/Application\ Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli"
# Get the list of items
IFS=$'\n' items=($(kb --list-profile-names))
# Get the current item
current_item=$(kb --show-current-profile-name)
# Find the index of the current item
for i in {1..$#items}; do
if [[ "${items[$i]}" == "$current_item" ]]; then
current_index=$i
break
fi
done
# Determine the next index
if [[ $current_index -eq $#items ]]; then
next_index=1
else
next_index=$((current_index + 1))
fi
# Select the next item
next_profile="${items[$next_index]}"
kb --select-profile $next_profile
echo "$next_profile selected"
@humblehacker
Copy link
Author

Then I assign it to the hotkey ⌘⌥Space. First, disable that hotkey combo in System Settings → Keyboard → Keyboard Shortcuts → Input Sources, if enabled. Then use Keyboard Maestro to run the script using the hotkey combo. I tried setting up a Mac Shortcut to do the same, and it sorta worked. But for unknown reasons some apps (Discord, for example), would block the shortcut. Keyboard Maestro just works.

@channinghsu
Copy link

So Nice!!

@humblehacker
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment