https://github.com/wicksome/iterm-launcher
🕹 AppleScript code to help you run iTerm2
https://github.com/wicksome/iterm-launcher
applescript iterm iterm-launcher iterm-window iterm2 iterm2-theme macos
Last synced: 4 months ago
JSON representation
🕹 AppleScript code to help you run iTerm2
- Host: GitHub
- URL: https://github.com/wicksome/iterm-launcher
- Owner: wicksome
- Created: 2017-07-23T17:43:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-03T05:13:03.000Z (almost 8 years ago)
- Last Synced: 2025-06-03T22:02:11.321Z (4 months ago)
- Topics: applescript, iterm, iterm-launcher, iterm-window, iterm2, iterm2-theme, macos
- Language: AppleScript
- Homepage:
- Size: 2.46 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# iTerm Launcher
> iTerm helper using AppleScript.
build env:
- macOS: Sierra 10.12.6
- iTerm2: Build 3.1.5## Demo

```sh
$ ./demo/run 2 4
Compiling /Users/user/git/iTerm-launcher/app/lib/iterm.applescript...
v2.0
```## Example code
```applescript
-- 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:
```applescript
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:
```applescript
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 itermsplitPane(ITERM_WINDOW, 2, 2) of iterm
```### `runCmdAllPanes(windowId: int, command: String)`
Example:
```applescript
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 itermrunCmdAllPanes(ITERM_WINDOW, "ls -al") of iterm
```### `runCmd(windowId: int, command: String)`
Example:
```applescript
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 itermrunCmd(ITERM_WINDOW, "echo 'This is current active pane'") of iterm
```### `runCmdPane(windowId: int, paneId: int, command: String)`
Example:
```applescript
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 itermrunCmdPane(ITERM_WINDOW, 2, "echo 'This is second pane'") of iterm
```### `runCmdEachPanes(windowId: Int, commands: Array)`
Example:
```applescript
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 itermrunCmdEachPanes(ITERM_WINDOW, [¬
"ls -al",¬
"htop",¬
"ps -ef | grep java"¬
]) of iterm
```### `sendKeystroke(keystroke: String)`
Example:
```applescript
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 itermsendKeystroke("CMD-OPT-i") of iterm
```## Reference
- https://www.iterm2.com/documentation-scripting.html