From ruby-talk Thu Mar 25 15:22:16 2004 From: "Jason Voegele" Date: Thu, 25 Mar 2004 15:22:16 +0000 To: ruby-talk Subject: Re: Detecting hardware with Ruby Message-Id: <42055.12.174.169.66.1080228127.squirrel () std5 ! imagineis ! com> X-MARC-Message: https://marc.info/?l=ruby-talk&m=108022819321066 Jamis Buck said: > Here's a rather off-the-wall question: how would I go about detecting > the presence of external hardware in Ruby? Specifically, sometimes my > laptop is attached to an external monitor, and sometimes it isn't. Just > before X starts, I'd like to have a Ruby script that runs and checks to > see if the monitor is present, and if it isn't, chooses a different > server layout from the XF86Config file. > > Or is there already a solution to this that I haven't found? I solved this problem by using init scripts. I have two init scripts called setup_home and setup_work. These scripts copy alternate versions of configuration files depending on whether I'm at work (attached to external monitor, keyboard, etc.) or at "home" (unattached laptop). I have one of these two scripts start depending on the runlevel. I can then choose a run level at boot time, which is very easy with GRUB, and these scripts will choose the right settings for me. Granted, this is not quite the same as "just before X starts", but you can at least choose at boot time which environment you want to have set up. I have a more detailed description of this at: http://forum.libranet.com/viewtopic.php?t=3908&highlight= If you want to follow the hardware detection route, you can probably write a simple wrapper around Kudzu. -- Jason Voegele "There is an essential core at the center of each man and woman that remains unaltered no matter how life's externals may be transformed or recombined. But it's smaller than we think." -- Gene Wolfe, The Book of the Long Sun