How To Make/Create a Script and Run it ?

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
newbie@mint

How To Make/Create a Script and Run it ?

Post by newbie@mint »

Hello guys,

Recently i found a script for disabling mouse acceleration in linux via google.It had following text


#wait for the desktop to settle
sleep 5

#gets the hardware id's of all mice plugged into the system
hardwareIds=$(xinput | grep -i mouse | awk '{print substr($(NF-3),4)}')

#turn off mouse acceleration
for i in $hardwareIds
do
xinput set-prop ${i} 'Device Accel Profile' -1
xinput set-prop ${i} 'Device Accel Velocity Scaling' 1

i want to know how to execute this script .in windows we had .bat file just double click its does every thing ...but in linux how to do it?


other methods/working scripts for disabling acceleration is appreciated


Thanks:)
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
newbie@mint

Re: How To Make/Create a Script and Run it ?

Post by newbie@mint »

User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: How To Make/Create a Script and Run it ?

Post by xenopeek »

It's an incomplete script. It looks like to be missing at least the first line (should be something like "#!/usr/bin/env bash") and last line (should be "done"). As you've quoted it here, this will not work. Looking at your link that would also not work as it's missing the first line.

Just like on Windows you can execute script files on Linux by just double-clicking them in your file manager. There are three differences with Windows:
  • Linux doesn't care about file extensions. You can name your script whatever you want. Some folks use the extensions .sh to indicate the file is a shell script.
  • Linux does require you to mark the script file as being executable. You do that in the file properties (from right-click menu in the file manager), on the permissions tab.
  • There are many languages you can use to write scripts: shell, Python, JavaScript, and many more.
The part you quoted is a shell script, using commands available also on the terminal. The default shell on Linux Mint is called bash. A good introduction to become more familiar with the shell and also touching on shell scripts is: http://en.flossmanuals.net/command-line/.

All that said, the better way to disable mouse acceleration is to configure X. To do that run this command (assuming you're on Cinnamon):

Code: Select all

gksudo gedit /etc/X11/xorg.conf.d/50-mouse-acceleration.conf
And put the following text in it:

Code: Select all

Section "InputClass"
	Identifier "My Mouse"
	MatchIsPointer "yes"
	Option "AccelerationProfile" "-1"
	Option "AccelerationScheme" "none"
	Option "AccelSpeed" "-1"
EndSection
Save and close the file. Reboot to activate it. Note that this disables mouse acceleration for all users. If you want to disable mouse acceleration only for you then try adding the following command to Startup Applications:

Code: Select all

sh -c 'xset m 0 0'
You can also run the command "xset m 0 0" yourself on the terminal to immediately disable mouse acceleration to see how that would be before implementing it.
Image
newbie@mint

Re: How To Make/Create a Script and Run it ?

Post by newbie@mint »

thanks :) can u make that script complete with that syntax that u mentioned earlier ? i read somewhere that xset has some problem
newbie@mint

Re: How To Make/Create a Script and Run it ?

Post by newbie@mint »

xenopeek wrote:It's an incomplete script. It looks like to be missing at least the first line (should be something like "#!/usr/bin/env bash") and last line (should be "done"). As you've quoted it here, this will not work. Looking at your link that would also not work as it's missing the first line.

Just like on Windows you can execute script files on Linux by just double-clicking them in your file manager. There are three differences with Windows:
  • Linux doesn't care about file extensions. You can name your script whatever you want. Some folks use the extensions .sh to indicate the file is a shell script.
  • Linux does require you to mark the script file as being executable. You do that in the file properties (from right-click menu in the file manager), on the permissions tab.
  • There are many languages you can use to write scripts: shell, Python, JavaScript, and many more.
The part you quoted is a shell script, using commands available also on the terminal. The default shell on Linux Mint is called bash. A good introduction to become more familiar with the shell and also touching on shell scripts is: http://en.flossmanuals.net/command-line/.

All that said, the better way to disable mouse acceleration is to configure X. To do that run this command (assuming you're on Cinnamon):

Code: Select all

gksudo gedit /etc/X11/xorg.conf.d/50-mouse-acceleration.conf
And put the following text in it:

Code: Select all

Section "InputClass"
	Identifier "My Mouse"
	MatchIsPointer "yes"
	Option "AccelerationProfile" "-1"
	Option "AccelerationScheme" "none"
	Option "AccelSpeed" "-1"
EndSection
Save and close the file. Reboot to activate it. Note that this disables mouse acceleration for all users. If you want to disable mouse acceleration only for you then try adding the following command to Startup Applications:

Code: Select all

sh -c 'xset m 0 0'
You can also run the command "xset m 0 0" yourself on the terminal to immediately disable mouse acceleration to see how that would be before implementing it.


i get following error when i save
Could not find the file /etc/X11/xorg.conf.d/50-mouse-acceleration.conf.
Please check that you typed the location correctly and try again.
Locked

Return to “Scripts & Bash”