Class: WorkOn::MacTerminal

Inherits:
AbstractTerminal show all
Includes:
Appscript
Defined in:
lib/work_on/terminals/mac_terminal.rb

Overview

Native Mac OS X implementation uses rb-appscript

Defined Under Namespace

Classes: MacTab, MacWindow

Instance Method Summary collapse

Methods inherited from AbstractTerminal

#execute, #selected_tab, #selected_window

Constructor Details

#initializeMacTerminal

Returns a new instance of MacTerminal.



10
11
12
13
# File 'lib/work_on/terminals/mac_terminal.rb', line 10

def initialize
  @appscript = app("Terminal.app")
  @process  = app("System Events").application_processes['Terminal']
end

Instance Method Details

#new_windowObject



28
29
30
31
32
33
34
# File 'lib/work_on/terminals/mac_terminal.rb', line 28

def new_window
  prev = selected_window
  @process.keystroke('n', :using => :command_down)
  window = selected_window
  prev.select!
  window
end

#windowsObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/work_on/terminals/mac_terminal.rb', line 15

def windows
  @appscript.windows.get.map! do |window|
    # it seems this returns far too many windows (some of them don't even exist)
    # so we check a property which will error when something is wrong
    begin
      window.selected.get
      MacWindow.new self, @process, window
    rescue
      nil
    end
  end.compact! # don't forget to remove the nil values
end