Morozilnic_2

Rocksmith Runner

Jun 12th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.50 KB | None | 0 0
  1. #!/bin/bash
  2. # This fixes keyboard issues in Rocksmith when Karabiner Elements is installed
  3.  
  4. # Stop/start procedure taken from Karabiner sources:
  5. # https://github.com/tekezo/Karabiner-Elements/blob/master/src/share/launchctl_utility.hpp
  6. # enable/disable commands throw errors left and right, but somehow work.
  7. # I do not dare change the commands.
  8.  
  9.  
  10. # <config>
  11. service_path="/Library/LaunchAgents/org.pqrs.karabiner.karabiner_console_user_server.plist"
  12. karabiner_cli="/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli"
  13. # </config>
  14.  
  15. escaped_karabiner_cli="$(echo "$karabiner_cli" | sed 's/ /\\ /g')"
  16.  
  17. echo "You should add following line to /etc/sudoers:"
  18. echo
  19. echo "$(id -un)    ALL = NOPASSWD: $escaped_karabiner_cli --copy-current-profile-to-system-default-profile, $escaped_karabiner_cli --remove-system-default-profile"
  20. echo
  21. echo "Correct way: open terminal and run: EDITOR=nano sudo visudo"
  22. echo "Scroll to the end of the file, paste line, press Ctrl+X, then press \"Y\""
  23. echo
  24. echo "************************************"
  25. echo
  26. echo "Attempting to launch Rocksmith"
  27.  
  28. echo "Unloading Karabiner's system default profile"
  29. sudo "$karabiner_cli" --remove-system-default-profile >/dev/null 2>&1
  30. if [[ $? -eq 0 ]]; then
  31.     echo "Karabiner's system default profile WAS loaded, will restore"
  32.     restore_profile=true
  33. else
  34.     echo "Karabiner's system default profile WAS NOT loaded"
  35.     restore_profile=false
  36. fi
  37.  
  38. domain_target="gui/$(id -u)"
  39.  
  40. echo "Unloading Karabiner itself"
  41. launchctl bootout "$domain_target" "$service_path" 2>&1 | grep "Could not find specified service" >/dev/null 2>&1
  42. if [[ $? -ne 0 ]]; then
  43.     echo "Karabiner WAS loaded, will restore"
  44.     reload=true
  45.     launchctl disable "$service_path" >/dev/null 2>&1
  46. else
  47.     echo "Karabiner WAS NOT loaded"
  48.     reload=false
  49. fi
  50.  
  51. echo "Opening Rocksmith"
  52. open steam://run/221680
  53. echo "Waiting a bit for Rocksmith to load"
  54.  
  55. # Works even with a second of delay, but since Rocksmith's
  56. # unskipable startup sequence is ~30 seconds you won't notice anything
  57. sleep 15
  58.  
  59. if [[ "$reload" = true ]]; then
  60.     echo "Reloading Karabiner"
  61.     launchctl enable "$service_path" >/dev/null 2>&1
  62.     launchctl bootstrap "$domain_target" "$service_path" >/dev/null 2>&1
  63.     launchctl enable "$service_path" >/dev/null 2>&1
  64.  
  65.     sleep 5
  66. fi
  67.  
  68. if [[ "$restore_profile" = true ]]; then
  69.     echo "Restoring Karabiner's system default profile"
  70.     sudo "$karabiner_cli" --copy-current-profile-to-system-default-profile >/dev/null 2>&1
  71. fi
Advertisement
Add Comment
Please, Sign In to add comment