Skip to content

Instantly share code, notes, and snippets.

@joshstrange
Created September 26, 2019 19:19
Show Gist options
  • Save joshstrange/ae60bc02d6103816d8f1e207d474c98d to your computer and use it in GitHub Desktop.
Save joshstrange/ae60bc02d6103816d8f1e207d474c98d to your computer and use it in GitHub Desktop.
import log from './logger';
import {find} from 'lodash';
function move(window: Window, screen: Screen | null) {
if(window.isVisible() && screen !== null) {
window.setTopLeft({x: screen.flippedVisibleFrame().x, y: screen.flippedVisibleFrame().y});
}
}
function moveAndFull(window: Window, screen: Screen | null) {
if(window.isVisible() && screen !== null) {
window.setTopLeft({x: screen.flippedVisibleFrame().x, y: screen.flippedVisibleFrame().y});
window.maximize();
}
}
function getScreen(screens: Screen[], id: string): Screen | null {
return find(screens, (screen) => {
return screen.identifier() === id;
}) || null;
}
Key.on('z', ['ctrl', 'alt'], () => {
log('messages');
const screens = (Screen.all() as any);
let location = null;
const laptopId = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
const locations: {[key: string]: {
farRight: string,
middle: string,
laptop: string,
farLeft: string
}} = {
home: {
farRight: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
middle: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
laptop: laptopId,
farLeft: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
},
office: {
farRight: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
middle: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
laptop: laptopId,
farLeft: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
}
};
let farRightScreen: Screen | null = null;
let laptopScreen: Screen | null = getScreen(screens, laptopId);
let farLeftScreen: Screen | null = null;
let middleScreen: Screen | null = null;
if(screens.length > 1) {
// Just match a single screen in a location
for(const loc in locations) {
if(getScreen(screens, locations[loc].farRight)) {
location = loc;
}
}
// Default until I setup work
if(location === null) {
log('Unknown location, using fallbacks');
farRightScreen = screens[0];
laptopScreen = screens[1];
farLeftScreen = screens[3];
middleScreen = screens[2];
} else {
log('Detected we are at: ' + location);
farRightScreen = getScreen(screens, locations[location].farRight);
laptopScreen = getScreen(screens, locations[location].laptop);
farLeftScreen = getScreen(screens, locations[location].farLeft);
middleScreen = getScreen(screens, locations[location].middle);
}
} else {
// If we just have the laptop fullscreen everything on it
farRightScreen = laptopScreen;
laptopScreen = laptopScreen;
farLeftScreen = laptopScreen;
middleScreen = laptopScreen;
}
screens.forEach((screen: Screen) => {
(screen.windows() as any).forEach((window: Window) => {
const name = window.app().name();
switch(name) {
case 'Slack':
moveAndFull(window, laptopScreen);
break;
case 'IntelliJ IDEA':
moveAndFull(window, farRightScreen);
break;
case 'Google Chrome':
moveAndFull(window, middleScreen);
break;
case 'iTerm2':
move(window, farRightScreen);
break;
case 'Sequel Pro':
moveAndFull(window, farLeftScreen);
break;
default:
log('No Logic: ' + window.app().name());
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment