How to check for a mouse and disable the trackpad

So I love my new massive desktop replacement of a laptop.  It’s fast, has plenty of RAM (for now at least), and plenty of Cores.  But it suffers from some of the same old issues every other laptop with a touchpad causes me.  When typing, it occasionally causes my cursor to end up in really strange places on my screen which results in messed up words or variable names.  On my MacBook Pro and in Windows I could disable the touchpad as soon as a mouse was connected.  I spent days trying to find the same settings on Linux and then ran across a few articles written by people who just wanted to turn off the trackpad for good.  That sounds good until you forget your mouse at home.  So I decided I needed to write my own script.  In a mere 38 lines(without comments) I came up with a script that looked to see if my mouse was connected and if so disable the trackpad.  If the mouse disappears or is removed the trackpad is re-enabled within 30 second.  If you want to use this script you will want to do a few things first:

  1. remove your mouse
  2. run “xinput list” determine what the system thinks your trackpad is called 
  3. plug-in the external mouse/pointer
  4. run “xinput list” again and determine what the system thinks it’s name is

My trackpad comes up as a ALPS GlidePoint.  If yours is different, which it likely will be, then you need to replace ‘ALPS GlidePoint’ in line 5 with the name of your trackpad.  If it is the same name then you don’t have to do anything with line 5.

My mouse comes up as ‘Logitech USB Receiver’ cause that sounds like a mouse right?  Well it is really the name of the wireless receiver for my mouse.  I shorted the name to just ‘USB Receiver’ in the hopes that any future wireless mice I may buy will use that part of the same name.  (Yeah I know there is about a 0% chance of that happening but I can dream can’t I?)  If yours is different, which like above it likely probably be, replace ‘USB Receiver’ in line 6 below.  If it’s the same then you don’t have to do anything with line 6.

The complete script can be found at this link.

One thing I did above that you may want to try in your scripts was to use the logger command instead of echo.  Logger uses the syslog subsystem and lets you write whatever you want to the default log for syslog.  Where to write is of course configurable if you need it to go somewhere else.  A word of warning though, logger will not move on if there is nothing to log.  It freezes and waits for you.  So like I did above, check to see if there is something in the variable before using it with logger.  Logger is available on most *nix versions.  If it’s missing you can normally find it as part of a syslog related package.

 

Sudo or not to Sudo…

I love SUDO….It let’s me audit who became root or ran certain commands…It keeps me from having to remember Roots password on all of the systems I use.  That then let’s me set really crazy passwords for Root.  The problem is that except for Ubuntu no one setups any groups or users to be able to run anything with it.  Sudo is one of the most powerful tools for managing users access to critical commands.  It let’s you audit what has been done and by who.  As long as you take the time to define the programs and make everyone not just do “sudo su -“.  For my home stuff though I am the only Linux Admin.  I probably will be until my son or daughter get old enough.  So setting myself up with sudo access on all my machines isn’t that big a risk.  So for all of those systems you don’t have it setup for automatically here is a link to a quick how to at Linux Journal to help you get it set up.  Thanks to Walt Jevack for pointing me to the link…