Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Created September 18, 2014 15:07
Show Gist options
  • Save aaronj1335/24f6d2d212aa22248e14 to your computer and use it in GitHub Desktop.
Save aaronj1335/24f6d2d212aa22248e14 to your computer and use it in GitHub Desktop.
/* 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]
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment