Skip to content

Instantly share code, notes, and snippets.

@sebcode
Created March 12, 2017 14:38
Show Gist options
  • Save sebcode/2ae6ecd6c638b7b0e9175024b03c22a0 to your computer and use it in GitHub Desktop.
Save sebcode/2ae6ecd6c638b7b0e9175024b03c22a0 to your computer and use it in GitHub Desktop.
JXA: Programmatically open a new iTerm tab with a specified command
#!/usr/bin/osascript -l JavaScript
// Open a new iTerm tab with a specified command.
// Usage example: ./openTermCommand.js '/usr/local/bin/vim /tmp/test.txt'
function run(argv) {
const iTerm = Application('iTerm')
iTerm.includeStandardAdditions = true
iTerm.activate()
const command = argv[0]
let win = iTerm.currentWindow()
if (win == null) {
win = iTerm.createWindowWithDefaultProfile({ command })
} else {
win.createTabWithDefaultProfile({ command })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment