I like to use middle mouse button emulation, because my middle mouse button is a scroll wheel and it takes a lot of pressure to register a click. This gets physically painful pretty quickly.
I find it much easier to just click the left and right mouse buttons simultaneously. And I use this feature all the time.
I have a script in ~/scripts/mouse.sh that does this:
#!/bin/bash
# Enable middle button emulation
# from https://askubuntu.com/a/201825/54278
if [[ -n ${DISPLAY} ]]; then
pointer1="MX Master"
id1=$(xinput | awk -F= "/$pointer1.*pointer/ {print \$2}" | cut -f1)
xinput set-prop "${id1}" "libinput Middle Emulation Enabled" 1
fi
This works well, but I have to run it manually every time I reboot.
I've created ~/.config/autostart/mouse.sh.desktop. These are the contents:
[Desktop Entry]
Type=Application
Exec=/home/david/.scripts/mouse.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_AU]=Mouse
Name=Mouse
Comment[en_AU]=Middle button emulation
Comment=Middle button emulation
My problem is that my script doesn't do anything on login.
I still have to open a terminal and run my script before middle mouse button emulation works.
I've tried removing the if [[ -n ${DISPLAY} ]]; then condition, and I've tried adding a sleep at the start of the script.
I've also tried adding the contents of my script to ~/.profile.
None of these things have worked. This has been bugging me for years!
Thanks for having a look :-)
Edits
- Also tried
Exec=/bin/bash /home/david/.scripts/mouse.sh. Thanks @PRATAP - Ubuntu 19.04, though it also hasn't worked in the last few versions, including 18.04
- Tried deleting the .desktop file and using the Startup Applications GUI
- Tried removing the
if [[ -n ${DISPLAY} ]]; thencondition - I had a flash of inspiration and tried using
Exec=/usr/bin/xterm -e /home/david/.scripts/mouse.sh- also no luck

/bin/bash /home/user/scripts/mouse.shand it is working well.. https://i.stack.imgur.com/SzV1c.jpg – PRATAP Jun 10 '19 at 05:14/bin/bashbefore the script and it seems to be working now - thanks! Kind of can't believe something so simple annoyed me for so long! – david_nash Jun 10 '19 at 06:53~/.config/autostart, so if I use the GUI it shows the same/bin/bash /home/david/.scripts/mouse.shin the command field – david_nash Jun 10 '19 at 23:16