Skip to content

Instantly share code, notes, and snippets.

@kfix
Last active January 14, 2024 06:46
Show Gist options
  • Save kfix/6dd55721766ff9fae0dd to your computer and use it in GitHub Desktop.
Save kfix/6dd55721766ff9fae0dd to your computer and use it in GitHub Desktop.
debugging iterm JS applescript window indexing failures
#!/usr/bin/osascript -l JavaScript
var iTerm = Application("iTerm");
iTerm.includeStandardAdditions = true;
iTerm.activate()
var new_win = function() {
var myNewWindow = iTerm.createWindowWithDefaultProfile({command: "/bin/bash"});
// https://github.com/gnachman/iTerm2/search?q=iTermNewWindowCommand
console.log("New window created: " + Automation.getDisplayString(myNewWindow, true));
return myNewWindow;
}
function run(argv) {
console.log(Automation.getDisplayString(iTerm.windows(), true));
var win = new_win();
console.log(Automation.getDisplayString(iTerm.windows(), true));
//console.log(iTerm.windows.whose({name: {_contains: 'bash'}})().length);
console.log(win.index());
}
// https://gitlab.com/gnachman/iterm2/issues/3910
// defaults write NSGlobalDomain NSScriptingDebugLogLevel 1
// syslog -w 0 -k Facility com.googlecode.iterm2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment