Launching a second session of SketchUp programmatically

I am trying to launch a second session of SU programmatically from another script. The second session should start with the a specified user script and exit. I am on Mac OSX.

At the moment I am using:

cmd = 'open -n -a sketchUp ' + su_file + ' --args -RubyStartup ' + mc_script
pid = spawn cmd

(You would use start on Windows).

Here su_file and mc_script are an SU file and a ruby script respectively.

This works, but I have a couple of issues:

  1. Most of the times I have to click on the new Sketchup icon on the dock in order for the script to begin to run.
  2. Sometimes SU starts, but the script is not executed and I have to launch it from the Ruby console manually.

Any suggestion? Is there a better way to do this?

I have only ever used it more directly, for a test example…
if mc_script.rb contains the line


and su_file is any skp copied to tmp…

su_file = "/private/tmp/abc.skp"
mc_script = "/private/tmp/mc_script.rb"
%x(open -n -a SketchUp "#{su_file}" --args -RubyStartup "#{mc_script}")

using spawn I would also make sure the paths are “wrapped” by using .inspect

cmd = 'open -n -a SketchUp ' + su_file.inspect + ' --args -RubyStartup ' + mc_script.inspect
pid = spawn cmd

I would also check the running SU version to ensure it was opening the same…

# First we get the path to the current parent version of SketchUp, this is the easiest
# way I've found to ensure the right version restarts when more than one version is open.
    #CUR_APP_PATH = (ENV["IG_ROOT"]).split("/")[0..-3].join("/").freeze.inspect unless defined? CUR_APP_PATH
    CUR_APP_PATH = $:.grep(/SketchUp\./)[0].split('/Contents')[0].inspect unless defined? CUR_APP_PATH
    #sup = Sketchup.find_support_file('SketchUp.exe').tr("/", "\\")

# Next we get the process identity [pid] of the actual running version of SketchUp.
    CUR_APP_PID = unless defined? CUR_APP_PID

then to use with open

"open -a #{CUR_APP_PATH}"


1 Like

Thanks John. Good tips.

I have added 2 seconds pause after spawn (or %x) and this seems to solve the issue that I was having.