Last active
March 28, 2024 13:28
-
-
Save ghall89/ee70d69bf1c2056b266dc4b79a71c12e to your computer and use it in GitHub Desktop.
Open multiple iTerm tabs in the same directory and run individual commands
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
| // paste this script in Script Editor on macOS | |
| iTerm = Application('iTerm2') | |
| iTerm.includeStandardAdditions = true; | |
| // change to the path to your directory | |
| var dir = '/path/to/project' | |
| var win | |
| // checks if an iTerm window already exists | |
| if (iTerm.currentWindow()) { | |
| win = iTerm.currentWindow(); | |
| } else { | |
| win = iTerm.createWindowWithDefaultProfile(); | |
| } | |
| // change to the commands you'd like to run | |
| var commands = [ | |
| 'npx serverless offline', | |
| 'npx nx dev frontend' | |
| ]; | |
| for (var i = 0; i < commands.length; i++) { | |
| if (win.tabs.length < i + 1) { | |
| win.createTabWithDefaultProfile(); | |
| } | |
| win.tabs[i].sessions[0].write({ | |
| text: 'cd ' + dir, | |
| newline: true | |
| }); | |
| win.tabs[i].sessions[0].write({ | |
| text: commands[i], | |
| newline: true | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment