sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Ruby script to detect OS

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 1.6k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      scott216
      last edited by

      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
      
      1 Reply Last reply Reply Quote 0
      • TIGT Online
        TIG Moderator
        last edited by

        (RUBY_PLATFORM.downcase =~ /darwin/) == nilreturn true if it's run on a PC, else it's on a MAC...

        TIG

        1 Reply Last reply Reply Quote 0
        • S Offline
          scott216
          last edited by

          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
          
          
          1 Reply Last reply Reply Quote 0
          • TIGT Online
            TIG Moderator
            last edited by

            That should do it...
            BUT add the missing (
            **%(#FF0000)[(]**RUBY_PLATFORM.downcase =~ /darwin/)
            You can also separate the require "sketchup.rb" out of the test...

            TIG

            1 Reply Last reply Reply Quote 0
            • A Offline
              Aerilius
              last edited by

              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).

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement