我正在尝试编写一个快速脚本,该脚本将关闭终端应用程序除当前窗口之外的所有窗口。该脚本使用 MacRuby 和脚本桥。这是我到目前为止所拥有的:
#!/usr/local/bin/macruby
framework "Foundation"
framework "ScriptingBridge"
terminal = SBApplication.applicationWithBundleIdentifier("com.apple.Terminal")
terminal.windows[2].close while terminal.windows.count > 1
当我尝试运行此程序时,出现以下错误:
undefined method `close' for #<TerminalWindow:0x40033b0e0> (NoMethodError)
这种方法似乎与 AppleScript 配合得很好。有人知道为什么这里失败吗?
最佳答案
我找到了 TerminalWindow
API 的副本 here 。使用它,我需要做的就是:
TerminalSaveOptionsNo = 'no '.unpack('N').first
terminal.windows[1].closeSaving(TerminalSaveOptionsNo, savingIn: nil)
关于ruby - 使用 MacRuby 和脚本桥关闭窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12774308/