Skip to content

Instantly share code, notes, and snippets.

@ghall89
Last active March 28, 2024 13:28
Show Gist options
  • Select an option

  • Save ghall89/ee70d69bf1c2056b266dc4b79a71c12e to your computer and use it in GitHub Desktop.

Select an option

Save ghall89/ee70d69bf1c2056b266dc4b79a71c12e to your computer and use it in GitHub Desktop.
Open multiple iTerm tabs in the same directory and run individual commands
// 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