Skip to content

Instantly share code, notes, and snippets.

@jewel12
Last active December 11, 2015 22:39
Show Gist options
  • Save jewel12/4671136 to your computer and use it in GitHub Desktop.
Save jewel12/4671136 to your computer and use it in GitHub Desktop.
// アプリにフォーカスする。アプリが起動していなければ起動する。
var launch_and_focus = function(app_name) {
var launch = function(app_names, win) {
if( _.any(app_names, function(name){ return name == app_name; }) ) {
return;
}
win.doOperation(
slate.operation('shell', {
'command' : '/usr/bin/open -a ' + app_name,
'waitForExit' : true
})
);
};
return function(win){
var app_names = [];
slate.eachApp(function(app_obj){ app_names.push(app_obj.name()); });
launch(app_names, win);
win.doOperation( slate.operation('focus', {'app' : app_name}) );
};
};
var key_binds = {};
key_binds['1:alt'] = launch_and_focus('Google Chrome');
key_binds['2:alt'] = launch_and_focus('iTerm');
key_binds['3:alt'] = launch_and_focus('Emacs');
key_binds['4:alt'] = launch_and_focus('Skype');
key_binds['5:alt'] = launch_and_focus('Things');
slate.bindAll(key_binds);
// oo というアプリにフォーカスしてる時、次は xx というアプリにフォーカスする
slate.bind('j:alt', function(win) {
var focus_apps = {
'iTerm' : 'Emacs',
'Emacs' : 'iTerm'
};
var app_name = win.app().name();
if (!(app_name in focus_apps)) return;
win.doOperation(
slate.operation('focus', {'app' : focus_apps[app_name]})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment