Class: Threeman::Frontends::MacTerminal

Inherits:
Threeman::Frontend show all
Defined in:
lib/threeman/frontends/mac_terminal.rb

Instance Attribute Summary

Attributes inherited from Threeman::Frontend

#options

Instance Method Summary collapse

Methods inherited from Threeman::Frontend

#bash_script, #initialize, #paned_command_names, #sort_commands

Constructor Details

This class inherits a constructor from Threeman::Frontend

Instance Method Details

#run_commands(commands) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/threeman/frontends/mac_terminal.rb', line 12

def run_commands(commands)
  events = Appscript.app("System Events")

  terminal = Appscript.app("Terminal")
  terminal.activate

  terminal_controller = events.processes['Terminal']

  commands.each_with_index do |command, index|
    if index == 0
      terminal.do_script("")
    else
      sleep 0.3 # Terminal is slow and its scripting API is prone to misbehavior; wait for it to finish doing the thing we just did

      terminal_controller.keystroke("t", using: [:command_down])
      terminal.do_script("", in: terminal.windows[0])
    end

    sleep 0.3
    terminal_controller.keystroke("cd #{Shellwords.escape command.workdir}\n")
    terminal_controller.keystroke(bash_cmd(command) + "\n")
  end
end