Last active
May 22, 2018 15:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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