Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This fixes keyboard issues in Rocksmith when Karabiner Elements is installed
- # Stop/start procedure taken from Karabiner sources:
- # https://github.com/tekezo/Karabiner-Elements/blob/master/src/share/launchctl_utility.hpp
- # enable/disable commands throw errors left and right, but somehow work.
- # I do not dare change the commands.
- # <config>
- service_path="/Library/LaunchAgents/org.pqrs.karabiner.karabiner_console_user_server.plist"
- karabiner_cli="/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli"
- # </config>
- escaped_karabiner_cli="$(echo "$karabiner_cli" | sed 's/ /\\ /g')"
- echo "You should add following line to /etc/sudoers:"
- echo
- echo "$(id -un) ALL = NOPASSWD: $escaped_karabiner_cli --copy-current-profile-to-system-default-profile, $escaped_karabiner_cli --remove-system-default-profile"
- echo
- echo "Correct way: open terminal and run: EDITOR=nano sudo visudo"
- echo "Scroll to the end of the file, paste line, press Ctrl+X, then press \"Y\""
- echo
- echo "************************************"
- echo
- echo "Attempting to launch Rocksmith"
- echo "Unloading Karabiner's system default profile"
- sudo "$karabiner_cli" --remove-system-default-profile >/dev/null 2>&1
- if [[ $? -eq 0 ]]; then
- echo "Karabiner's system default profile WAS loaded, will restore"
- restore_profile=true
- else
- echo "Karabiner's system default profile WAS NOT loaded"
- restore_profile=false
- fi
- domain_target="gui/$(id -u)"
- echo "Unloading Karabiner itself"
- launchctl bootout "$domain_target" "$service_path" 2>&1 | grep "Could not find specified service" >/dev/null 2>&1
- if [[ $? -ne 0 ]]; then
- echo "Karabiner WAS loaded, will restore"
- reload=true
- launchctl disable "$service_path" >/dev/null 2>&1
- else
- echo "Karabiner WAS NOT loaded"
- reload=false
- fi
- echo "Opening Rocksmith"
- open steam://run/221680
- echo "Waiting a bit for Rocksmith to load"
- # Works even with a second of delay, but since Rocksmith's
- # unskipable startup sequence is ~30 seconds you won't notice anything
- sleep 15
- if [[ "$reload" = true ]]; then
- echo "Reloading Karabiner"
- launchctl enable "$service_path" >/dev/null 2>&1
- launchctl bootstrap "$domain_target" "$service_path" >/dev/null 2>&1
- launchctl enable "$service_path" >/dev/null 2>&1
- sleep 5
- fi
- if [[ "$restore_profile" = true ]]; then
- echo "Restoring Karabiner's system default profile"
- sudo "$karabiner_cli" --copy-current-profile-to-system-default-profile >/dev/null 2>&1
- fi
Advertisement
Add Comment
Please, Sign In to add comment