sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Will this work on Mac OS?

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 137 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.
    • N Offline
      niccah
      last edited by

      Hey at all!

      A first release of my plugin comes closer and closer, but I have no possibilities to check my code on Mac OS... To avoid very basic problems, I would like to ask you: What do you think? Will this code work?

      ` fileContent = "Java -jar " + File.dirname(FILE) + "\Model2GCode.jar"

      fileName = File.dirname(FILE) + "\Model2GCode."
      fileName << "command" if (RUBY_PLATFORM.downcase.include?("darwin")) # Mac OS
      fileName << "bat" if (RUBY_PLATFORM.downcase.include?("mswin")) # Windows

      file = File.new(fileName, "w")
      file.write(fileContent)
      file.close

      UI.openURL(File.dirname(FILE) + "\Model2GCode.bat") if (RUBY_PLATFORM.downcase.include?("mswin")) # Windows
      UI.openURL(File.dirname(FILE) + "\Model2GCode.command") if (RUBY_PLATFORM.downcase.include?("darwin")) # Mac OS`

      @Thom: You wrote a nice post, at which you explained, at which code parts one has to be careful because of the differences between Win / Mac. Could you please give me a link to this post? I could not find it anymore πŸ˜’

      Thanks for your help!

      1 Reply Last reply Reply Quote 0
      • N Offline
        niccah
        last edited by

        @aerilius said:

        File.join("folder1", "folder2", "filename")

        Oh yes, you are right! This is the next point on my list. However, thanks a lot for the hint!!!

        OSX = ( Object::RUBY_PLATFORM =~ /(darwin)/i ? true : false ) unless defined?(OSX) WIN = ( not OSX ) unless defined?(WIN)

        This looks very smart! Thanks!! πŸ˜„

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

          Hi,
          first, backslashes are a relict from when Windows did not need to support nested folder structures. File path delimiters differ between operating systems and because of that Ruby has super cool abstracted methods to deal with that, ie.
          [File.join](http://www.ruby-doc.org/core-1.8.6/File.html#method-c-join)("folder1", "folder2", "filename")
          So it is best to clean up a file path immediately when you receive it (from the UI etc.):
          ` # This resolves relative paths and symbolic links and makes sure all delimiters will be later the same.
          path = File.expand_path( File.dirname(FILE) )

          This joins the paths.

          filename = File.join(path, "Model2GCode.")`

          In order to avoid repetition, you can define operating system constants once:
          ` OSX = ( Object::RUBY_PLATFORM =~ /(darwin)/i ? true : false ) unless defined?(OSX)
          WIN = ( not OSX ) unless defined?(WIN)

          if WIN
          do_something
          elsif OSX
          do_something_else
          end`

          For the rest, I have to leave the field for actual OS X users.

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by

            hi,

            you may need a java version test, as mac no longer ships with it pre-installed, it does however recomend installing as part of the start-up sequence.

            so, from ruby console

            java_version=(`java -version 2>&1`).split("\n")[0].to_s.split[-1]
            "1.6.0_37"
            

            john

            learn from the mistakes of others, you may not live long enough to make them all yourself...

            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