Skip to content

Instantly share code, notes, and snippets.

@macournoyer
Created October 30, 2008 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save macournoyer/20999 to your computer and use it in GitHub Desktop.
Save macournoyer/20999 to your computer and use it in GitHub Desktop.
Open a new tab in Terminal
#!/usr/bin/env ruby
# Open a new tab in Terminal
# usage: tab [cmd]
# If cmd is specified, it will be run in new tab while old tab is reactivated.
# If no cmd, new tab is activated
require "rubygems"
require "appscript"
include Appscript
window = app("Terminal").windows.first
current_tab = window.selected_tab.get
# create new tab
app("System Events").keystroke("t", :using => :command_down)
new_tab = window.tabs.last
# switch back to original tab if set to run init cmd
window.set(window.selected_tab, :to => current_tab) unless ARGV.empty?
# and change dir
app("Terminal").do_script("cd #{Dir.pwd}", :in => new_tab)
# Run init cmd if specified
app("Terminal").do_script(ARGV.join(" "), :in => new_tab) unless ARGV.empty?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment