Ruby script to detect OS
-
I don't know much about ruby scripts, but I'm trying to do something I hope is simple. I use SU on several computers (Mac & Win7) and I just set up folder syncing for my plugins folder so they would all have the same plugins. I'm using a 3DConnexion 'mouse' and it loads drivers differently on Mac vs Win 7. I'd like a ruby script that can detect which OS I'm on, then load the appropriate drivers for 3DConnexion.
For example:
If Windows require 'sketchup.rb' require '3DxSketchUp/3DxSketchUp.dll' file_loaded("3DxSketchUp.rb") else require 'sketchup.rb' require '3DxSketchUp.bundle.plugin/Contents/MacOS/3DxSketchUp.bundle' file_loaded("3DxSketchUp.rb") endif
-
(RUBY_PLATFORM.downcase =~ /darwin/) == nil
return true if it's run on a PC, else it's on a MAC... -
Thanks! Is the write way to do the if statement
If RUBY_PLATFORM.downcase =~ /darwin/) == nil # Windows require 'sketchup.rb' require '3DxSketchUp/3DxSketchUp.dll' file_loaded("3DxSketchUp.rb") else # Not Windows require 'sketchup.rb' require '3DxSketchUp.bundle.plugin/Contents/MacOS/3DxSketchUp.bundle' file_loaded("3DxSketchUp.rb") end
-
That should do it...
BUT add the missing (
**%(#FF0000)[(]**RUBY_PLATFORM.downcase =~ /darwin/)
You can also separate therequire "sketchup.rb"
out of the test... -
That (edit: scott's) is already almost ruby code. This should do it:
module TDxSkp WIN = ( (Object;;RUBY_PLATFORM =~ /mswin/i || Object;;RUBY_PLATFORM =~ /mingw/i) unless defined?(WIN) OSX = ( Object;;RUBY_PLATFORM =~ /(darwin)/i ? true ; false ) unless defined?(OSX) if WIN require 'sketchup.rb' require '3DxSketchUp/3DxSketchUp.dll' file_loaded("3DxSketchUp.rb") elsif OSX require 'sketchup.rb' require '3DxSketchUp.bundle.plugin/Contents/MacOS/3DxSketchUp.bundle' file_loaded("3DxSketchUp.rb") end end # module
http://sketchucation.com/forums/viewtopic.php?f=180&t=34631&p=305368
We use proper operating system names because we are not detecting hardware. I'm not sure if that's the namespace (TDxSkp
) that they use, but our constants should better not float in top level namespace.However note that 3DConnexion is a binary plugin and adds content to the Ruby environment that we can not check for errors (or we can find but not fix them).
Advertisement