Applescript (osascript): opening split panes in iTerm 2 and performing commands

前端 未结 6 1252
生来不讨喜
生来不讨喜 2021-01-05 01:14

The following works to open two tabs in iTerm 2.

I can\'t seem to figure out how to get this to using split panes instead.

I\'ve tried appl

6条回答
  •  北荒
    北荒 (楼主)
    2021-01-05 01:57

    starting from @mklement0, this is my script that open a new tab, split in 4 panels and run comands:

    #!/usr/bin/env bash
    osascript <<-EOF
        set cmds to {"rabbitmq-server", "mongod", "redis-server", "htop"}
    
        tell application "iTerm"
            activate
            set myterm to (current terminal)
    
            tell myterm
                launch session "Default Session"
    
                # split vertically
                tell application "System Events" to keystroke "d" using command down
                delay 1
                # previus panel
                tell application "System Events" to keystroke "[" using command down
                delay 1
                # split horizontally
                tell application "System Events" to keystroke "d" using {shift down, command down}
                delay 1
                # next panel
                tell application "System Events" to keystroke "]" using command down
                delay 1
                # split horizontally
                tell application "System Events" to keystroke "d" using {shift down, command down}
    
                set n to count of cmds
                repeat with i from 1 to n
                    # next panel
                    tell application "System Events" to keystroke "]" using command down
                    delay 1
                    tell the current session to write text (item i of cmds)
                end repeat
            end tell
    
        end tell  
    EOF
    

提交回复
热议问题