Store Useful Linux Script

Last updated:September 14th 2022, 20:51

Change scroll speed
  • there are two files here:
    • .sh is the well-written script to open a GUI to interact with the package imwheel for ubuntu
      • note: the last 2 lines help fixing the lacking function of back and forth button when using chrome
    • .desktop is to execute the .sh file without using terminal
  • Both of these file must be set to be executable by doing this:
    • chmod +x ScrollSpeed.sh & chmod +x ScrollSpeed.desktop

ScrollSpeed.desktop

1
2
3
4
5
6
7
8
[Desktop Entry]

Name=ScrollSpeed
Comment=
Exec=/home/tungnguyen/AutoLaunchScript/ScrollSpeed/ScrollSpeed.sh
Icon=/home/tungnguyen/AutoLaunchScript/ScrollSpeed/icon.png
Terminal=false
Type=Application

ScrollSpeed.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
cd "${0%/*}"
#!/bin/bash
# Version 0.1 Tuesday, 07 May 2013
# Comments and complaints http://www.nicknorton.net
# GUI for mouse wheel speed using imwheel in Gnome
# imwheel needs to be installed for this script to work
# sudo apt-get install imwheel
# Pretty much hard wired to only use a mouse with
# left, right and wheel in the middle.
# If you have a mouse with complications or special needs,
# use the command xev to find what your wheel does.
#
### see if imwheel config exists, if not create it ###
if [ ! -f ~/.imwheelrc ]
then

cat >~/.imwheelrc<<EOF
".*"
None, Up, Button4, 1
None, Down, Button5, 1
Control_L, Up, Control_L|Button4
Control_L, Down, Control_L|Button5
Shift_L, Up, Shift_L|Button4
Shift_L, Down, Shift_L|Button5
EOF

fi
##########################################################

CURRENT_VALUE=$(awk -F 'Button4,' '{print $2}' ~/.imwheelrc)

NEW_VALUE=$(zenity --scale --window-icon=info --ok-label=Apply --title="Wheelies" --text "Mouse wheel speed:" --min-value=1 --max-value=100 --value="$CURRENT_VALUE" --step 1)

if [ "$NEW_VALUE" == "" ];
then exit 0
fi

sed -i "s/\($TARGET_KEY *Button4, *\).*/\1$NEW_VALUE/" ~/.imwheelrc # find the string Button4, and write new value.
sed -i "s/\($TARGET_KEY *Button5, *\).*/\1$NEW_VALUE/" ~/.imwheelrc # find the string Button5, and write new value.

cat ~/.imwheelrc
imwheel -kill
imwheel --kill --buttons "4 5"