slate.log('Loading config')

var getKeystroke = function(key) {
    return key + ':ctrl,shift'
}

var screens = {
    laptop: '1280x800',
    thunderbolt: '2560x1440'
}

// Operations

var operations = {}
var windowMargin = 20

/**
 * Applies the operation or list of operations
 */
operations.apply = function(window, operation) {
    if (Array.isArray(operation)) {
        operation.forEach(function(subOperation) {
            operations.apply(window, subOperation)
        })
    } else {
        window.doOperation(operation)
    }
}

operations.moveToHalfLeft = function() {
    return slate.operation('move', {
        x: 'screenOriginX',
        y: 'screenOriginY',
        width: 'screenSizeX / 2',
        height: 'screenSizeY'
    })
}

operations.moveToHalfRight = function() {
    return slate.operation('move', {
        x: 'screenOriginX + screenSizeX / 2',
        y: 'screenOriginY', 
        width: 'screenSizeX / 2',
        height: 'screenSizeY'
    })
}

operations.maximize = function() {
    return slate.operation('move', {
        x: 'screenOriginX',
        y: 'screenOriginY',
        width: 'screenSizeX',
        height: 'screenSizeY'
    })
}

operations.pad = function(top, right, bottom, left) {
    var xPadding = right + left
    var yPadding = top + bottom
    return [
        slate.operation('resize', {width: '-' + xPadding, height: '-' + yPadding}),
        slate.operation('nudge', {x: '+' + left, y: '+' + top})
    ]
}

// Application operation by screen count

var appsOperationsByScreenCount = {
    'Google Chrome': {
        1: operations.maximize(),
        2: [
            slate.operation('throw', {screen: screens.thunderbolt}),
            operations.moveToHalfLeft(),
            operations.pad(windowMargin, windowMargin / 2, windowMargin, windowMargin)
        ]
    },
    iTerm: {
        1: [
            operations.maximize(),
            operations.pad(windowMargin, windowMargin, windowMargin, windowMargin),
        ],
        2: [
            slate.operation('throw', {screen: screens.thunderbolt}),
            operations.moveToHalfRight(),
            operations.pad(windowMargin, windowMargin, windowMargin, windowMargin / 2)
        ]
    }
}

var refresh = function() {
    var screenCount = slate.screenCount()
    slate.eachApp(function(app) {
        var appOperationsByScreenCount = appsOperationsByScreenCount[app.name()] || []
        var appOperations = appOperationsByScreenCount[screenCount] || []
        app.eachWindow(function(window) {
            operations.apply(window, appOperations)
        })
    })
}

slate.on('screenConfigurationChanged', refresh)

refresh()

//

slate.bind(getKeystroke('r'), slate.operation('relaunch'))

slate.log('Config loaded')

@@ -1502,20 +1502,23 @@
 nt%0A%0Avar 
-apps
+browser
 Operatio
@@ -1523,53 +1523,13 @@
 ions
-ByScreenCount = %7B%0A    'Google Chrome': %7B%0A    
+ = %7B%0A
     
@@ -1550,28 +1550,24 @@
 maximize(),%0A
-    
     2: %5B%0A   
@@ -1563,36 +1563,32 @@
    2: %5B%0A        
- 
-   
 slate.operation(
@@ -1628,36 +1628,32 @@
 bolt%7D),%0A        
-    
 operations.moveT
@@ -1661,28 +1661,24 @@
 HalfLeft(),%0A
-    
         oper
@@ -1752,27 +1752,130 @@
 in)%0A    
-    %5D%0A    %7D
+%5D%0A%7D;%0A%0Avar appsOperationsByScreenCount = %7B%0A    'Google Chrome': browserOperations,%0A    'Firefox': browserOperations
 ,%0A    iT

Include Firefox