7

on my development workstation I often have to start the same commands every morning.

zeus start, zeus server (booting rails via zeus), redis-server, and like 3 others.

I know a lot of people would say have them running all the time but I do a lot of work on my own stuff and it wigs me out having all of those running while I'm working on separate rails projects.

Is there some kind of advanced alias I can make which starts all of these from one command, ideally by programmatically splitting the window (like ⌘-D).

I'm using iTerm2 with oh-my-zsh.

I wouldnt mind if they were all in the same window I suppose (somehow running as background processes) however I do need to sometimes look at the output, and work with the output from each command, so I'm not sure how that would work.

Thanks!

Tallboy
  • 261
  • 1
  • 4
  • 14

3 Answers3

7

You can easily call this from iTerm2 directly to simulate pressing D:

osascript -e 'tell application "System Events" to key code 2 using command down'

For this to work you want to start the programs in background, since otherwise you cannot run osascript:

some-command &
osascript -e '…'

From there on you'll land in a new iTerm2 window, so you need to use the write text option in AppleScript to run further shell commands. See here for more: How do I set up an AppleScript to open a new iTerm2 tab and change the directory?

slhck
  • 235,242
1

the answer here is a bit outdated.. here is an example script that does somethign similar:

tell application "iTerm"
    tell current window
        -- create a tab for background db stuff
        create tab with default profile
        tell current session
            write text "mongod &"
            write text "redis-server &"
        end tell
        close current tab

        -- create tab to run aioc server
        create tab with default profile
        tell current session
            write text "title server"
            write text "aactivate"
            write text "arunserver"
            -- split tab vertically to run scheduler
            split vertically with default profile
        end tell

        -- run scheduler
        tell last session of last tab
            write text "title scheduler"
            write text "aactivate"
            write text "ascheduler"
            -- split tab vertically to run main controller
            split vertically with default profile
        end tell

        -- run main_controller
        tell last session of last tab
            write text "title main_controller"
            write text "aactivate"
            write text "amain_controller"
            -- split tab vertically to run aggregator
            split vertically with default profile
        end tell

        tell last session of last tab
            write text "title aggregator"
            write text "aactivate"
            write text "aggregator"
        end tell




    end tell
end tell
abbood
  • 1,354
0

I recently created a CLI tool to split panes, it uses the python API rather than AppleScript as AppleScript API is deprecated

Repo

Install:

pip3 install iterm-pane-spliter
iterm-pane-spliter <json-structure>

Examples

2 panes vertically split

For this:

-------------------
|        |        |
|        |        |
|   1    |    2   |
|        |        |
|        |        |
-------------------

the json structure you should provide is:

Tip: just add more numbers to add more vertical panes

[
  [1, 2]
]

so you will need to run:

iterm-pane-spliter "[[1, 2]]"

Some crazy structure

-------------------
|     1     |     |
| --------- |  5  |
|     |     |     |
|     |  7  | --- |
|  2  |     |  3  |
|     | --- | --- |
|     |  8  |  6  |
| --- | --- | --- |
|        4        |
-------------------

the json structure you should provide is:

[
    [1, 1, 5],
    [2, 7, 5],
    [2, 7, 3],
    [2, 8, 6],
    [4, 4, 4]
]

so you will need to run:

iterm-pane-spliter "[[1, 1, 5], [2, 7, 5], [2, 7, 3], [2, 8, 6], [4, 4, 4]]"

there are more examples in the repo README