Moonstar@lemmy.fmhy.mlOPtoLinux@lemmy.ml•Scripting Question - xdotool and ratbagctlEnglish
1·
1 year agoThe results have made me realize that the bash way of doing this is just not worth attempting, and a Python script is much more simple. At the end of the day, I ended up using this GIST with a custom handler function:
https://gist.github.com/dperelman/c1d3c966d397ff884abb8b3baf7990db
class MouseProfile(Enum):
DEFAULT = 0
BLOONS = 1
GAMING_COMMON = 2
CALL_OF_DUTY = 3
REALM_GRINDER = 4
def handle_change(new_state: dict):
"""
Using `libratbag`, switch the profile of the mouse based on the active window title.
"""
# Get the title of the active window
title: str = new_state['title']
profile: MouseProfile = MouseProfile.DEFAULT
match title:
case "BloonsTD6":
profile = MouseProfile.BLOONS
case "Realm Grinder":
profile = MouseProfile.REALM_GRINDER
case _:
if title:
if search(r"^Call of Duty.*", title):
profile = MouseProfile.CALL_OF_DUTY
elif search(r"^Deep Rock Galactic.*", title):
profile = MouseProfile.GAMING_COMMON
# Send the ratbag command to switch the profile
run(["ratbagctl", "Logitech", "profile", "active", "set", str(profile.value)], stdout=PIPE, stderr=PIPE)
Don’t you mean from 1 to 11? (And 3 is not a valid option.) Sorry, I saw an opening for a stupid joke and had to jump.