sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Ruby Version for Sketchup 8.0 M1 on Mac ??

    Scheduled Pinned Locked Moved Developers' Forum
    41 Posts 6 Posters 3.6k Views 6 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
      slbaumgartner
      last edited by

      @driven said:

      @dan rathbun said:

      I don't have a Mac.. but there must be a way for you guys to point that link at your up to date "system" Ruby.

      the path to version 8.5

      /Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions/A/Ruby

      but how to point it to system version??

      Not for the faint of heart, but here's how:

      • quit sketchup
      • open a terminal window
      • cd /Applications/Google\ SketchUp \8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions
      • sudo mv A A.orig
      • sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8 A

      Restart SketchUp, open a Console window, and type VERSION. If all went well, it should report the same version as when you type ruby -e "puts VERSION" in a console window.

      To undo this hack, in the same Versions folder:

      • sudo rm A
      • sudo mv A.orig A
      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        Hi Steve,
        I run as an admin, but not root, I need sudo for anything outside user space.
        'Content' folders should have User read/write permissions, I thought.
        I also run multiple copies of SU, the path for this one differs from norm and yours. [that may be the splat]

        the other thing I have now added sleep 1 and a return before the cd / to reopen SU in both methods.

        I may have done blanket permission change using Sketchup.app >> right click >> more info and change for all enclosed files, but I don't think so... but that should work to avoid 'sudo'.
        alternatively do that to your 'User' folder after installing SU there?

        just using the bits needed for a restart seems handy as well.

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

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @John: The global constant VERSION is deprecated because every class and module should have one that specifies it's version, but if the global is defined, it will get inherited into every class and module, and it's easy to assume the inherited one is a specific module version.

          Example at the console:
          module Dan; end %(#008000)[>> nil] Dan.module_eval("VERSION") %(#008000)[>> 1.8.6]

          Oh look, module Dan is version 1.8.6 ?

          Not really:
          Dan::VERSION %(#008000)[>> Error: #<NameError: (eval): uninitialized constant Dan::VERSION> (eval)]

          Use RUBY_VERSION instead. (As well as the other constants that are prefixed RUBY_ ... please.)


          @Steve: Please don't quote codeblocks. Besides wasting space (and SCF bandwidth,) it just clones errors, and the original poster of the code may make corrections to the code, which will not be propagated into your quote. (I wish the quote feature would auto-strip them and insert a link back to the quoted post.)

          (pssst... you can edit your post and delete the quoted code.)

          ๐Ÿ˜„

          I'm not here much anymore.

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

            @driven said:

            Hi Steve,
            just got back and tested your method, works a treat, so I worked out a Ruby Console 'none sudo' version that works here, if it works for you I'll make it into a toggle button for switching from inside SU...

            yes Dan I'll wrap it in a module...
            john

            Hi John,

            On my Mac, the folders and files involved all have root ownership and rwxr-xr-x permissions, so without sudo I could change nothing. When I tried this script, SketchUp crashed (no bugsplat, just vanished!), and nothing changed. You aren't running as root are you? I can see how, after changing permissions, your script would be useful for toggling back and forth between versions, but I don't understand how it can work without either that tweak or sudo?

            Steve

            P.S. OK Dan, I deleted the code block

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

              @driven said:

              Hi Steve,
              I run as an admin, but not root, I need sudo for anything outside user space.
              'Content' folders should have User read/write permissions, I thought.
              I also run multiple copies of SU, the path for this one differs from norm and yours. [that may be the splat]

              the other thing I have now added sleep 1 and a return before the cd / to reopen SU in both methods.

              I may have done blanket permission change using Sketchup.app >> right click >> more info and change for all enclosed files, but I don't think so... but that should work to avoid 'sudo'.
              alternatively do that to your 'User' folder after installing SU there?

              just using the bits needed for a restart seems handy as well.

              Hmm...there is a school of though that says ordinary users shouldn't be able to tamper within the subfolders of an app bundle, since they can destabilize the app in arbitrary ways. I once ran a utility that "fixes problems due to permissions", and I wonder if it reset the SU folders and files based on that thinking? Horse is out of the barn now, so without removing and reinstalling SU it's impossible for me to be sure. Maybe if another Mac user is watching this, they can look at their folders before either of our tweaks and tell us what permissions they see? The answer would be important so that your script could be shared successfully.

              On a more basic level, after switching to 1.8.7, why would someone want to switch back? The only reason I have thought of is if you are writing plugins for the general Mac community, you might want to verify that they run on the as-installed SU with 1.8.5. So far, I haven't run into any old ones that won't run on 1.8.7. And if I do, provided they were distributed as open code, I'd be more inclined to fix them than to switch back to 1.8.5 just for their sake!

              I had seen the problem Dan cites when I used the new Ruby console the Trimble guys posted on GitHub - VERSION on it returns 0.0.1; you have to use RUBY_VERSION to get the right string.

              Steve

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

                @slbaumgartner said:

                Hmm...there is a school of though that says ordinary users shouldn't be able to tamper within the subfolders of an app bundle, since they can destabilize the app in arbitrary ways.

                I've never considered myself ordinary maybe ornery root and admin read/write same for V8 on my wife's machine

                @unknownuser said:

                On a more basic level, after switching to 1.8.7, why would someone want to switch back?

                I was thinking that this would be more for Dev's and/or the curious, and if you add an -n flag, to the open cmd you can have both at once in two separate instances of Sketchup.

                @unknownuser said:

                So far, I haven't run into any old ones that won't run on 1.8.7.

                Well, oddly enough the code I first had for this, would only work from 1.8.5 >> 1.8.7 but not back down.
                It took me ages to find the same layout that would work in both Thread.new requires a block in 1.8.7, but will work in 1.8.5 with or without.

                @unknownuser said:

                you have to use RUBY_VERSION to get the right string.

                Steve
                I always do, i didn't realise VERSION would work at all until you posted it...
                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
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @driven said:

                  @slbaumgartner said:

                  ... you have to use RUBY_VERSION to get the right string.
                  I always do, I didn't realize VERSION would work at all until you posted it... john

                  From the Ruby v1.8.6-p398 API Core Reference, for Object constants:
                  Object_Constants_1_8_6.PNG
                  The caption "obsolete constants" is supposed to be in a right margin, but the DarkFish doc generator didn't do that. It shoved the right margin text under the first item in the left column.

                  A check of the online doc for v1.9.x shows they have finally been removed.
                  see: Ruby Core v1.9.3: Object

                  ๐Ÿค“

                  I'm not here much anymore.

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

                    Dan,

                    I find those parts of the Ruby documentation ambiguous, as the phrase "obsolete constants" displays below VERSION when I view the page, as if, in the example you posted, it applies to RELEASE_DATE and PLATFORM but not to VERSION. In any case, it is clear that we should use RUBY_VERSION as there are examples on the table where using VERSION breaks

                    Steve.

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

                      Hi Steve,
                      just got back and tested your method, works a treat, so I worked out a Ruby Console 'none sudo' version that works here, if it works for you I'll make it into a toggle button for switching from inside SU...

                      # Thread #1 is running here
                      newRuby = Thread.new{
                        # Thread #2 runs this code
                      `cd /Applications/Sketchup.app/Contents/Frameworks/Ruby.framework/Versions
                       mv A A.orig
                       ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8 A 
                      cd /
                      open /Applications/Sketchup.app
                       `
                       }
                      # Thread #1 runs this code
                      if RUDY_VERSION == "1.8.5"
                      newRuby
                      Sketchup.send_action('terminate;')
                      end
                      
                      
                      
                      # Thread #1 is running here
                      oldRuby = Thread.new {
                        # Thread #2 runs this code
                      `cd /Applications/Sketchup.app/Contents/Frameworks/Ruby.framework/Versions
                      rm A
                      mv A.orig A 
                      cd /
                      open /Applications/Sketchup.app
                      ` 
                      }
                      # Thread #1 runs this code
                      if RUBY_VERSION == "1.8.7"
                      oldRuby
                      Sketchup.send_action('terminate;')
                      end
                      

                      yes Dan I'll wrap it in a module...
                      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
                      • D Offline
                        driven
                        last edited by

                        so, you need to double escape the system path, but single escape the ruby one.... aaahhhhhh

                        any testers, before I polish it?

                        puts "RUBY_VERSION = " + RUBY_VERSION # useful for debug...
                        # Thread #1 is running here  /Applications/Google\\ SketchUp\\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions
                        
                        def changeRuby
                        
                        if File.exists? "/Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions/A.orig"
                        Thread.new{
                          # Thread #2 runs this code
                        system("cd /Applications/Google\\ SketchUp\\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions
                        rm A
                        mv A.orig A
                        
                        ")
                        };
                        
                        UI.messagebox("changing to RUBY_VERSION 1.8.5")
                        else
                        # RUBY_VERSION === "1.8.5"
                        Thread.new{
                          # Thread #2 runs this code
                        system("cd /Applications/Google\\ SketchUp\\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions
                        mv A A.orig
                        ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8 A
                        
                        ")
                        };
                        
                        UI.messagebox("changing to RUBY_VERSION 1.8.7")
                        end #if
                        
                        end #def
                        
                        toolbar = UI;;Toolbar.new "mac_RUBY_VERSION"
                          # This toolbar toggles between 1.8.7 and 1.8.5
                        @mac_RUBY_VERSION = UI;;Command.new("change"){changeRuby;
                        Thread.new{
                          # Thread #3 runs this code
                        system("sleep 2
                        cd /
                        open /Applications/Google\\ SketchUp\\ 8/SketchUp.app
                        
                        ")
                        };
                        Sketchup.send_action('terminate;');
                        }
                        
                         @mac_RUBY_VERSION.large_icon = "/Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Resources/ReloadPage.png"
                         @mac_RUBY_VERSION.small_icon = "/Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Resources/ReloadPage.png"
                         @mac_RUBY_VERSION.tooltip = "Switch Ruby Version"
                         @mac_RUBY_VERSION.status_bar_text = "Switching Ruby Version on reload"
                         @mac_RUBY_VERSION.menu_text = "change_RUBY_VERSION"
                          toolbar = toolbar.add_item @mac_RUBY_VERSION
                          toolbar.show
                        
                        

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

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

                          ok,
                          I'm having an issue,
                          I've got a button version that works fine on one of my SU.app install paths but not the other, even this basic excerpt won't work

                          > if File.exists? "/Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions/A.orig"
                          Thread.new {
                            # Thread #2 runs this code
                          system("cd /Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions
                          rm A
                          mv A.orig A
                          
                          ")
                          };
                          
                          UI.messagebox("changing to RUBY_VERSION 1.8.5")
                          else
                          # RUBY_VERSION === "1.8.5"
                          Thread.new{
                            # Thread #2 runs this code
                          system("cd /Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions
                          mv A A.orig
                          ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8 A
                          
                          ")
                          };
                          
                          UI.messagebox("changing to RUBY_VERSION 1.8.7")
                          end #if
                          1
                          > File.exists? "/Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions/A.orig"
                          true
                          
                          
                          # SU returns  =>
                           RUBY_VERSION = 1.8.7
                          key = Units
                          value = 0.0
                          > if File.exists? "/Applications/Sketchup.app/Contents/Frameworks/Ruby.framework/Versions/A.orig"
                          Thread.new {
                            # Thread #2 runs this code
                          system("cd /Applications/Sketchup.app/Contents/Frameworks/Ruby.framework/Versions
                          rm A
                          mv A.orig A
                          
                          ")
                          };
                          
                          #UI.messagebox("changing to RUBY_VERSION 1.8.5")
                          else
                          # RUBY_VERSION === "1.8.5"
                          Thread.new{
                            # Thread #2 runs this code
                          system("cd /Applications/Sketchup.app/Contents/Frameworks/Ruby.framework/Versions
                          mv A A.orig
                          ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8 A
                          
                          ")
                          };
                          
                          #UI.messagebox("changing to RUBY_VERSION 1.8.7")
                          end #if
                          
                          #<Thread;0x12cd6f4c sleep>
                          >  File.exists? "/Applications/Sketchup.app/Contents/Frameworks/Ruby.framework/Versions/A.orig"
                          false
                          
                          

                          the only difference is the path
                          what does returning **1** as opposed to **#<Thread:0x12cd6f4c sleep>**

                          help.... SOLVED, it is odd how posting helps

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

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

                            @driven said:

                            so, you need to double escape the system path, but single escape the ruby one.... aaahhhhhh

                            any testers, before I polish it?

                            Ah the joy of escapes! You need one \ to preserve the space in a path used by Ruby itself, but \ to pass along \ to preserve the space when the path will be sent to the system. Ack!!

                            I'll be tied up for a day or two with holiday obligations, but will be glad to try this out when I get some free time.

                            Steve

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

                              Cheers,
                              I'll have added the /usr/bin/irb/ $LOAD_PATH array to it by then...
                              an auto version of this

                              begin
                              a=["/Library/Ruby/Site/1.8", "/Library/Ruby/Site/1.8/universal-darwin12.0", "/Library/Ruby/Site", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8/universal-darwin12.0", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0", "."]
                              a.each{|x| $; << x }
                              rescue Exception
                               print $!
                               print $!.backtrace.join("\n")
                              rescue StandardError
                               print $!
                               print $!.backtrace.join("\n")
                              rescue RuntimeError
                               print $!
                               print $!.backtrace.join("\n")
                              rescue
                               print $!
                               print $!.backtrace.join("\n")
                              end
                              $LOAD_PATH.uniq! # delete duplicate entries
                              puts $LOAD_PATH.sort.join("\n")
                              
                              

                              and also (ruby -r rubygems -e "p Gem.path")
                              digging through all my past efforts
                              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
                              • D Offline
                                driven
                                last edited by

                                @slbaumgartner said:

                                Ah the joy of escapes! You need one \ to preserve the space in a path used by Ruby itself, but \ to pass along \ to preserve the space when the path will be sent to the system. Ack!!

                                I found a new trick if you have @apPath=("/Applications/Google\ SketchUp\ 8/SketchUp.app") you can use it as ruby @apPath.to_s etc... or wrap it for a system call like this
                                (open -n $"#{@apPath}"\n)
                                I think that's very handy, 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
                                • S Offline
                                  slbaumgartner
                                  last edited by

                                  @driven said:

                                  Still not wrapped, as I think I'll add it to my ON_OFF.rb and rework that to add a few new tricks this exercise has exposed.
                                  However, this is now running in either of the two versions of SU I have installed at different Paths, and it should also add your native Ruby and Gem Paths on >1.8.5 [gems don't work on 1.8.5 unless you still have a full instal of both...]
                                  [attachment=0:28ht225z]<!-- ia0 -->rubyVersion_change.rb<!-- ia0 -->[/attachment:28ht225z]
                                  Should I delete all the other progression code? I did edit it to work, and it has a variety of other methods...

                                  John,

                                  Lots of problems with this code on my Mac. I'm pressed for time right now, will PM you later when I get a chance.

                                  Steve

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

                                    There's 2 potential problems I can see, the first is my need to check which version of SUv8 I'm using, as they share .plist, so I've re-coded all that and this should return the correct path regardless of version.
                                    Works without the hard coded version numbers on mine.
                                    If it does you could just swop it in and test further, or let me know.

                                    
                                    @SUversion=(Sketchup.version.to_s)
                                    stndSU=("/Applications/Google\ SketchUp\ 8/SketchUp.app")
                                    altSU=("/Applications/SketchUp.app")
                                    chkSU=("/Applications/Sketchup.app/Contents/Info.plist")
                                    if File.exists? chkSU
                                    f=(IO.readlines chkSU)
                                    k=(f.index "\t<key>CFBundleVersion</key>\n").to_i
                                    v=(k + 1)
                                    s=(f[v]).gsub("<string>","").gsub("</string>","").strip
                                    end
                                    if s === @SUversion
                                    @apPath=(altSU)
                                    else
                                    @apPath=(stndSU)
                                    end #if
                                    @apPath.freeze
                                    @verPath=("/Contents/Frameworks/Ruby.framework/Versions")
                                    @ourPath=(@apPath.to_s + @verPath.to_s)
                                    
                                    
                                    

                                    The second problem could be your permissions, which I can't check easily, but I could have a conditional that fails gracefully.
                                    john
                                    added @SUversion=(Sketchup.version.to_s) as first line so this should run as a standalone, it's already in the ruby...

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

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

                                      Update to the community: driven and I have got a plugin to do this Ruby swap nearly ready. Currently kicking it around to shake out any remaining bugs and packaging it for distribution. We'll put in the plugins forum soon.

                                      Steve

                                      1 Reply Last reply Reply Quote 0
                                      • Dan RathbunD Offline
                                        Dan Rathbun
                                        last edited by

                                        Just playin' devil's advocate:

                                        Must the switch be done from within SketchUp, requiring a restart... or can desktop shortcuts (aka symbolic links, for you unix-like peeps,) be created to start SketchUp running whatever Ruby version is desired ?

                                        (I had asked this question long ago, in a similar topic thread.)

                                        I'm not here much anymore.

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

                                          @dan rathbun said:

                                          Just playin' devil's advocate:

                                          Must the switch be done from within SketchUp, requiring a restart... or can desktop shortcuts (aka symbolic links, for you unix-like peeps,) be created to start SketchUp running whatever Ruby version is desired ?

                                          (I had asked this question long ago, in a similar topic thread.)

                                          Our switchover plugin is from within SketchUp and does require a restart (which it performs automatically for you). To select the version at launch time, you'd need to wrap it in a shell or Apple script that performs the shell commands I provided earlier. I don't think there is any way to tell SketchUp itself which Ruby to use as it launches...it behaves like it has a path to its distributed version coded into the executable.

                                          Steve

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

                                            @dan rathbun said:

                                            Just playin' devil's advocate:

                                            so unlike you,

                                            Dan at the time I made a few external auto_SU function menu items, no one was interested unless there inside SU, or maybe in an external editor menu.

                                            Main reason given was they didn't want to see SU Tools if they're not using SU... which is fair enough.

                                            I've pulled the 'reload part' out as a separate button[still in SU], and I use that all the time when testing stuff, sometimes I swap ruby versions first, sometimes I turn plugins on/off then 'reload SU' as a one click.

                                            I like it
                                            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
                                            • 2
                                            • 3
                                            • 1 / 3
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement