Last active
October 2, 2017 11:33
-
-
Save elnygren/4cb6104686e9cff415a7ba04cab7d1d8 to your computer and use it in GitHub Desktop.
Open new iTerm tabs with specific commands using AppleScript. Helpful when you want to automatise opening bigger projects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ----------------------------------------------------- | |
| -- iterm-opener by @elnygren | |
| -- This script runs each command in COMMANDS in a new iTerm2 tab. | |
| -- Useful for opening projects that require several windows. | |
| -- Usage: | |
| -- GUI | |
| -- 1. Open this file with Script Editor | |
| -- 2. add your commands | |
| -- 3. Save As (cmd+shift+opt+S) Application | |
| -- 4. Run like an App (from Finder) | |
| -- CLI | |
| -- 1. Open this file with any editor | |
| -- 2. add your commands and save normally | |
| -- 3. `osascript /path/to/iterm-opener.applescript` | |
| ----------------------------------------------------- | |
| set COMMANDS to {} | |
| -- add your commands here: | |
| -- e.g append(COMMANDS, "cd ~/myproject && npm start") | |
| append(COMMANDS, "") | |
| -- AppleScript doesn't allow multiline lists... | |
| on append(arr, x) | |
| copy x to the end of arr | |
| end append | |
| tell application "iTerm" | |
| ----------------------------------------------------- | |
| -- run each command in COMMANDS in a new iTerm tab -- | |
| ----------------------------------------------------- | |
| activate | |
| create window with default profile | |
| -- loop with index | |
| repeat with n from 1 to count of COMMANDS | |
| -- skip first because a new window comes with a single tab | |
| if n > 1 then | |
| tell current window | |
| create tab with default profile | |
| end tell | |
| end if | |
| -- open tab with the n:th command | |
| tell current session of current tab of current window | |
| write text (item n of COMMANDS) | |
| end tell | |
| end repeat | |
| end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment