Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3964152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:17:59+00:00 2026-05-20T03:17:59+00:00

The Ruby API to Google SketchUp has a function, open_file , but I can’t

  • 0

The Ruby API to Google SketchUp has a function, open_file, but I can’t find a close_file function. Since I have to batch process many files, I want to close each file before moving on to the next, otherwise the program will crash from memory exhaustion.

What is the best way to close SketchUp files programmatically?

I am using Mac OS X and am willing to use AppleScript functions to signal the window to close.

EDIT

I am considering a few approaches that have proven fruitless so far.

  1. Using the appscript Ruby gem, as described in this question. The problem here is that I cannot get SketchUp to recognize my installed gems.
  2. In a similar vein, I am trying to use osascript (a bash program that executes AppleScripts from the shell) to close the window. That is, I call out to the shell from SketchUp’s Ruby console window using one of the following:

    %x[osascript -e ‘tell application “SketchUp” to close window 1’]

    %x[osascript -e ‘tell application “SketchUp” to close window 1’ &]

    %x[osascript -e ‘tell application “SketchUp” to close every window’]

    %x[osascript -e ‘tell application “SketchUp” to close every window’ &]

    Whenever I try this second approach, SketchUp just freezes. However, when I execute any of these commands from an IRB or directly from the Bash prompt outside of SketchUp, I get the desired behavior: the model window closes (incidentally, the Ruby console window remains open, which is fine).

  3. Have a master script that launches a slave script to process each model. The slave will run within the Google SketchUp program while the master waits. When the slave is finished, it signals the master, and the master closes the SketchUp file. To do this interprocess communication, I tried using drb. However, when I try to require drb within SketchUp, I get the following message:

Error: LoadError: (eval):5:in ‘require’: no such file to load — drb

EDIT 2

Having a separate process continuously running that closes Google Sketchup windows using AppleScript when signaled is clumsy for a number of reasons. First, it’s ugly to have to have a separate process devoted to closing Sketchup windows. Second, the only effective way of communicating with the external script is through the creation of files, which is wasteful and the disk access may be slowing things down.

However, the most severe issue is that Sketchup is slow at responding to AppleScript commands. I have a pretty computation intensive script running in Sketchup, and it seems to starve the AppleScript response, which means that the osascript times out before the windows close. Sketchup only gets around to responding to AppleScript when there is a dialogue box prompt in Sketchup that pauses the execution of my computationally intensive script.

EDIT 3

I have modified my close_file function to pause execution of the script by displaying a dialog box. This essentially yields the current thread and allows the thread that responds to AppleScript commands to execute:

def close_file()
  f = '/temp/mutex.txt' # for finer control, use different mutex for each window you want closed
  File.new(f, 'w').close
  result = UI.messagebox "Click OK when window has closed."
end

Then the separate ruby script that closes windows via AppleScript will additionally have to click “OK” in the dialog box. AppleScript to do that is:

tell application "System Events"
    tell process "SketchUp"
        set frontmost to true
        keystroke return
    end tell
end tell

This modification is an improvement. It corrects the “most severe issue” mentioned in EDIT 2, but the other issues remain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:18:00+00:00Added an answer on May 20, 2026 at 3:18 am

    One solution is to have a separate process continuously running that will close Google Sketchup windows using AppleScript when signaled. The approach described here uses files to do the interprocess communication (drb did not seem to work).

    First, you have to make sure Sketchup supports AppleScripting. To do this, execute the following at the command prompt (with appropriate substitutions for different Sketchup versions, etc.):

    $ defaults write /Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Info NSAppleScriptEnabled -bool YES
    

    Now, create a separate file that will close Sketchup windows. Here is my closer.rb file:

    #!/usr/bin/ruby
    
    ## closer.rb ##
    
    def wait(f)
      while !File::exists?(f)
      end 
      File.delete(f)
    end
    
    def signal(f)
      File.new(f, 'w').close
    end
    
    while true
      wait('~/temp/mutex.txt')
      msg = %x[osascript -e 'tell application "SketchUp" to close every window'] 
      signal('~/temp/conf.txt')
    end
    

    Run this script from the shell. It waits until the file ~/temp/mutex.txt is created. Once the file is created, it runs osascript (essentially AppleScript) to close all the windows in Sketchup, and then signals that the windows were closed by creating a ~/temp/conf.txt file.

    Here is the client code (which can be placed in your Sketchup plugins) that signals the closer script:

    def wait(f)
      while !File::exists?(f)
      end 
      File.delete(f)
    end
    
    def signal(f)
      File.new(f, 'w').close
    end
    
    def close_file
      signal('~/temp/mutex.txt')
      wait('~/temp/conf.txt')
    end
    

    The close_file signals the closer script and then waits for a confirmation that the file was closed before returning. Now you can close files in Sketchup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue. Why do we have two?
Does anyone know of a good dictionary API or ruby library to lookup the
Ruby has a wealth of conditional constructs, including if / unless , while /
Ruby on Rails has magic timestamping fields that are automatically updated when a record
Ruby can add methods to the Number class and other core types to get
Ruby on Rails has a lot of ways to generate JavaScript. Particularly when it
Ruby is truly memory-hungry - but also worth every single bit. What do you
Ruby setters—whether created by (c)attr_accessor or manually—seem to be the only methods that need
Ruby's standard popen3 module does not work on Windows. Is there a maintained replacement
Ruby on Rails does not do multithreaded request-responses very well, or at least, ActiveRecord

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.