2

I'm trying to write a quick script that will close all but the current window for the terminal application. This script uses MacRuby and the Scripting Bridge. Heres' what I have so far:

#!/usr/local/bin/macruby

framework "Foundation"
framework "ScriptingBridge"

terminal = SBApplication.applicationWithBundleIdentifier("com.apple.Terminal")
terminal.windows[2].close while terminal.windows.count > 1

When I try to run this, I get the following error:

undefined method `close' for #<TerminalWindow:0x40033b0e0> (NoMethodError)

This approach seems to work fine with AppleScript. Does anybody know why it's failing here?

LandonSchropp
  • 10,084
  • 22
  • 86
  • 149

1 Answers1

2

I found a copy of the TerminalWindow API here. Using that, all I needed to do was:

TerminalSaveOptionsNo = 'no  '.unpack('N').first
terminal.windows[1].closeSaving(TerminalSaveOptionsNo, savingIn: nil)
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149