Skip to content

Instantly share code, notes, and snippets.

@CyrusNuevoDia
Last active May 22, 2018 15:49
Show Gist options
  • Save CyrusNuevoDia/624bcf79025e28351cf7dfe9abc16fd5 to your computer and use it in GitHub Desktop.
Save CyrusNuevoDia/624bcf79025e28351cf7dfe9abc16fd5 to your computer and use it in GitHub Desktop.
An AppleScript to get a Rails server, console, and general session open in iTerm.
#!/usr/bin/env osascript -l JavaScript
function open(name) {
var application = Application(name);
application.running() || application.open();
return application;
}
function bootstrapTerminal(project) {
var terminal = open("iTerm");
var action = terminal.windows.length ? "currentWindow" : "createWindowWithDefaultProfile";
var app = terminal[action]();
var tab = app.currentTab();
var left = tab.currentSession();
var bottom = left.splitHorizontallyWithSameProfile();
var right = left.splitVerticallyWithSameProfile();
var cd = "j " + project.toString();
left.write({ text: cd + " && bin/rails s" });
right.write({ text: cd + " && bin/rails c" });
bottom.write({ text: cd });
}
function run(argv) {
if (argv[0]) {
bootstrapTerminal(argv[0]);
} else {
console.error("Please pass a project name as an argument");
return 1;
}
if (argv[1]) {
open(argv[1]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment