Skip to content

wicksome/iTerm-launcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iTerm Launcher

iTerm helper using AppleScript.

build env:

  • macOS: Sierra 10.12.6
  • iTerm2: Build 3.1.5

Demo

preview

$ ./demo/run 2 4
Compiling /Users/user/git/iTerm-launcher/app/lib/iterm.applescript...
v2.0

Example code

-- Load iTerm script.
tell application "Finder" to set binPath to POSIX path of (container of (path to me) as text) & "app/bin/"
set iterm to load script file (currentPath & "iterm.scpt")

-- Use iTerm script.
set ITERM_WINDOW to newWindow() of iterm -- row, column

-- show version
log VERSION of iterm
-- Split pane
splitPane(ITERM_WINDOW, 2, 2) of iterm
-- run command to current pane
runCmd(ITERM_WINDOW, "echo 'This is active pane current'") of iterm
-- run command to all panes
runCmdAllPanes(ITERM_WINDOW, "echo 'all'") of iterm
-- run command to specific pane
runCmdPane(ITERM_WINDOW, 2, "echo 'This is second pane'") of iterm
-- run commands to each pane
runCmdEachPanes(ITERM_WINDOW, [¬
  "echo '1'",¬
  "echo '2'",¬
  "echo '3'"¬
]) of iterm
-- send keystroke
sendKeystroke("CMD-OPT-i") of iterm

Usage

newWindow(): windowId

Example:

tell application "Finder" to set binPath to POSIX path of (container of (path to me) as text) & "app/bin/"
set iterm to load script file (currentPath & "iterm.scpt")
set ITERM_WINDOW to newWindow() of iterm

splitPane(windowId: int, row: int, column: int)

Example:

tell application "Finder" to set binPath to POSIX path of (container of (path to me) as text) & "app/bin/"
set iterm to load script file (currentPath & "iterm.scpt")
set ITERM_WINDOW to newWindow() of iterm

splitPane(ITERM_WINDOW, 2, 2) of iterm

runCmdAllPanes(windowId: int, command: String)

Example:

tell application "Finder" to set binPath to POSIX path of (container of (path to me) as text) & "app/bin/"
set iterm to load script file (currentPath & "iterm.scpt")
set ITERM_WINDOW to newWindow() of iterm
splitPane(ITERM_WINDOW, 2, 2) of iterm

runCmdAllPanes(ITERM_WINDOW, "ls -al") of iterm

runCmd(windowId: int, command: String)

Example:

tell application "Finder" to set binPath to POSIX path of (container of (path to me) as text) & "app/bin/"
set iterm to load script file (currentPath & "iterm.scpt")
set ITERM_WINDOW to newWindow() of iterm
splitPane(ITERM_WINDOW, 2, 2) of iterm

runCmd(ITERM_WINDOW, "echo 'This is current active pane'") of iterm

runCmdPane(windowId: int, paneId: int, command: String)

Example:

tell application "Finder" to set binPath to POSIX path of (container of (path to me) as text) & "app/bin/"
set iterm to load script file (currentPath & "iterm.scpt")
set ITERM_WINDOW to newWindow() of iterm
splitPane(ITERM_WINDOW, 2, 2) of iterm

runCmdPane(ITERM_WINDOW, 2, "echo 'This is second pane'") of iterm

runCmdEachPanes(windowId: Int, commands: Array)

Example:

tell application "Finder" to set binPath to POSIX path of (container of (path to me) as text) & "app/bin/"
set iterm to load script file (currentPath & "iterm.scpt")
set ITERM_WINDOW to newWindow() of iterm
splitPane(ITERM_WINDOW, 2, 2) of iterm

runCmdEachPanes(ITERM_WINDOW, [¬
  "ls -al",¬
  "htop",¬
  "ps -ef | grep java"¬
]) of iterm

sendKeystroke(keystroke: String)

Example:

tell application "Finder" to set binPath to POSIX path of (container of (path to me) as text) & "app/bin/"
set iterm to load script file (currentPath & "iterm.scpt")
set ITERM_WINDOW to newWindow() of iterm
splitPane(ITERM_WINDOW, 2, 2) of iterm

sendKeystroke("CMD-OPT-i") of iterm

Reference