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
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developerworks/5268d9b5e70837bf6005 to your computer and use it in GitHub Desktop.
Save developerworks/5268d9b5e70837bf6005 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