[solved] how to keep running script for mouse sensitivity?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
TropiKo

[solved] how to keep running script for mouse sensitivity?

Post by TropiKo »

My razer Diamondback mouse has a dying cable and sometimes disconnects. It then recconnects and works OK.
I run a script manually whenever I need it but it's getting tedious.

Code: Select all

#!/bin/sh
xinput --set-prop "Razer Razer 1600dpi Mouse" "Device Accel Constant Deceleration" 2
xinput --set-prop "Razer Razer 1600dpi Mouse" "Device Accel Velocity Scaling" 1
Is there a way to make the script run as daemon or something so that whenever the mouse recconects it just keeps telling xinput to lower the sensitivity and disable accel?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
zargon12

Re: how to keep running script for mouse sensitivity?

Post by zargon12 »

Hi

Traditionally this could be done with a cron job, but I never do.

1) place your bash code in /home/youruser/.bashrc at the end of the file.
More on this later. If the file does not exist create it.

2) write your bash code as a function, e.g
function keepMouseAlive {
while [ 1 -eq 1 ]
do
xinput --set-prop "Razer Razer 1600dpi Mouse" "Device Accel Constant Deceleration" 2
xinput --set-prop "Razer Razer 1600dpi Mouse" "Device Accel Velocity Scaling" 1
sleep 5 #sleep 5 seconds
done
}

3 Invoke your keepMouseAlive function in your system startup folder.
This is usually found in your system settings menu entry. In
Linux Mint 17 Xfce you go to settings, session and startup,
application startup. In Cinnamon it will be somewhere else I
presume. Whenever Cinnamon or Xfce or whatever desktop starts the function
keepMouseAlive will be launched in the background.
add an entry as follows:
bash -i -c 'keepMouseAlive' &
DO NOT FORGET THE &. This says run the function in the background.
Otherwise it will launch and hang your system.

4) A more generalized way of doing this is to place your functions in files
in /usr/local/bin and source it from .bashrc.

in /usr/local/bin create a file - myFunctions.sh
place your function here. You can add as many functions as you want.
then in .bashrc code . /usr/local/bin/myFunctions
when bash starts all the functions are read into memory and are available
at the command prompt.

You can source as many files as you like. I.E. you can group them into
categories. network.sh, multimedia.sh, backups.sh, virtualization.sh...

Hope I haven't missed anything.

Best wishes

Murray
zargon12

Re: how to keep running script for mouse sensitivity?

Post by zargon12 »

Hi

As an addendum to above:

Line
then in .bashrc code . /usr/local/bin/myFunctions
Should read
then in .bashrc code . /usr/local/bin/myFunctions.sh


also you probably don't have ccess to /us/local/bin ( I have root access)
Instead create your own /home/username/bin folder and use that instead.

Murray
TropiKo

Re: how to keep running script for mouse sensitivity?

Post by TropiKo »

Thanks for the help.
I'm not sure I will need myFunctions.sh for now, startup command will do.
I also discovered xset mouse 0 1 to work just as well and with most USB mice.
Still you solved my issue, so thanks again.
zargon12

Re: how to keep running script for mouse sensitivity?

Post by zargon12 »

Glad you found a direct solution.

Time to edit your post as [Solved] I think.

Murray
JusTertii

Re: [solved] how to keep running script for mouse sensitivit

Post by JusTertii »

Glad it's all solved, but in case anyone else gets a similar problem -- I think this problem could also be fixed by making a udev rule for the dodgy mouse in question (but I may be mistaken). If you set it up right, it would then only run when the system detects that particular mouse plugged in.

Or, alternatively -- instead of fiddling around with your .bashrc file, you can simply add it to your startup applications. Eg:
In Menu -> Startup Applications, you add a new task. In command, put: sh "~/path-to-the-script/script.sh" and it should simply run the script on startup (if you really want it running in the background all the itme).
JusTertii

Re: [solved] how to keep running script for mouse sensitivit

Post by JusTertii »

gmilo2 wrote:@JusTertil do you know if it can detect a ps/2 mouse plugged in? I seem to remember there's some difficulty with detecting ps/2 devices plugged in.
I've only ever personally used it for USB devices, but based on this I think it'll work as long as you avoid matching with ATTR (easy to avoid using). I think this was the problem that came from debian a couple of years ago, but I haven't been around long enough to know for sure. AFAIK, it's all sorted out. I can't test my own because I don't have any PS/2 ports!

If you do manage it, I think UDEV rules are a more elegant solution than auto-running scripts at startup (although if his mouse is always plugged in, it comes to the same thing) but might be a bit more fiddly to set up.I'm sure there's a udev tutorial, either on this or the ubuntu forum somewhere.

But, gmilo2, if you do give it a go, I'd be interested to hear if it works out for you.
Locked

Return to “Scripts & Bash”