Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Get Coordinates For Windows With Mac's JavaScript For Automation

This pulls the window coordinates for a single app.

js
#!/usr/bin/env osascript -l JavaScript

const appName = "iTerm2";
const windowCount = Application(appName).windows.length;

for (let windowIndex = 0; windowIndex < windowCount; windowIndex ++) {
    const window = Application(appName).windows[windowIndex];
    const windowBounds = Application(appName).windows[windowIndex].bounds();
    console.log(window.name());
    console.log(
      `x: ${windowBounds.x} - y: ${windowBounds.y} - width: ${windowBounds.width} - height: ${windowBounds.height}`
    );
}

NOTE : This may not work with all apps. When setting window positions a different method needs to be used.