Skip to content

Instantly share code, notes, and snippets.

@developerworks
Forked from aaronj1335/repozish.js
Last active August 29, 2015 14:07
Show Gist options
  • Save developerworks/5268d9b5e70837bf6005 to your computer and use it in GitHub Desktop.
Save developerworks/5268d9b5e70837bf6005 to your computer and use it in GitHub Desktop.

Revisions

  1. @aaronj1335 aaronj1335 created this gist Sep 18, 2014.
    66 changes: 66 additions & 0 deletions repozish.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    /* global Application, ObjC, $ */

    /**
    * repozish.js
    *
    * this is an example of using os x yosemite's "JavaScript for Automation":
    *
    * https://developer.apple.com/library/prerelease/mac/releasenotes/interapplicationcommunication/rn-javascriptforautomation/index.html
    *
    * it repositions some windows based on some position settings. you can run
    * this from a terminal with:
    *
    * $ osascript repozish.js
    *
    * TODO: figure out how to read positions from/write positions to a file
    */

    // importing this gives us the `$.printf` function and probably some other
    // stuff
    ObjC.import('stdio');

    /**
    * positions of the windows
    *
    * you could query these with something like:
    *
    * var positions = ['Terminal', 'MacVim']
    * .reduce(function(positions, appName) {
    * var properties = Application(appName).windows[0].properties();
    * positions[appName] = properties.bounds;
    * return positions;
    * }, {});
    *
    * // print this stuff to stdout
    * $.printf(JSON.stringify(positions, null, 2));
    */

    var positions = {
    Terminal: {
    x: 3270,
    y: -388,
    width: 573,
    height: 1412
    },
    MacVim: {
    x: 2551,
    y: -388,
    width: 718,
    height: 1397
    }
    };

    /**
    * run
    *
    * this is like the 'main' function in C.
    *
    * @param args Array of command line args
    */
    function run(args) {
    Object.keys(positions).forEach(function(appName) {
    Application(appName).windows[0].properties = {
    bounds: positions[appName]
    };
    });
    }