Getting unique ID of a user's machine

In SketchUp 2014 (when we first switched to Ruby 2.x,) we had a similar issue.

I created a little patch script (at that time) to fix the situation, until it was fixed (SU2015 M0?)

backquote_patch.rb (1.2 KB)

# encoding: UTF-8
#  file : backquote_patch.rb
#
#  Windows ONLY : Ruby v1.9+
#  Needed as of SketchUp 2014 M0 RC4
#
#  v 1.0.0  -  2014-02-19

if RUBY_VERSION.to_f > 1.8 && RUBY_PLATFORM !~ /darwin/i

  # We are running under MS Windows
  if `ver`.empty? # patch global backquote method:

    module Kernel

      # The backquote method `() already has a module function copy: Kernel::`()
      # so we do not need to alias it, in order to access it's functionality.

      def backquote(cmd)
        #
        tempfile = nil
        raise(TypeError,'string argument expected.',caller) unless cmd.is_a?(String)
        #
        tempfile = ENV['TMP'].encode('UTF-8').gsub('\\','/')
        tempfile << '/backquote.out'
        #
        ::Kernel::method('`').call("#{cmd} > #{tempfile}")
        return File.read(tempfile)
        #
      rescue
        raise
      ensure
        if tempfile && File::exist?(tempfile)
          File::delete(tempfile) rescue nil
        end
      end

      # Override the private instance method #`() that all objects inherit,
      #  and rewire %x delimited execute strings, to use our backquote() patch:
      alias_method("`",:backquote)
      
    end # module Kernel

  end # conditional patch

end # if not OSX
2 Likes