LoginSignup
6
4

More than 5 years have passed since last update.

iTerm2 での pane を分けて作業開始を自動化する AppleScript

Posted at

command + shift + d の pane 分けに飽きた人に何かしら参考になれば幸いです。

こんなことやってる人がいるのかしらないですが、僕はやっているのですが..。
docker-compose 環境で作業することが多いです。なので、下図のようなのが僕の iTerm2 の定位置になっています。

スクリーンショット 2018-08-22 11.56.37 2.png

このポジションをつくるのに、毎回 command + shift + d とかで、pane を分割してとやっているのですが、これが飽きてしまいました。

めんどくさい動作↓
start_work.gif

これを簡単にやりたいとおもって、以下の shell script を書きました。

start_work.sh
osascript <<-EOF
tell application "iTerm2"
    # Split pane
    tell current session of current window
        split horizontally with default profile
        split vertically with default profile
    end tell

    # Exec commands
    tell first session of current tab of current window
        write text "until docker-compose exec rails bash; do; sleep 2; done"
    end tell
    tell second session of current tab of current window
        write text "docker-compose up"
    end tell
    tell third session of current tab of current window
        # write text "echo 3"
    end tell
end tell
EOF

これを、sh start_work.sh で叩くと3つの pane が開かれて、すこし楽しいです。

start_work_after.gif

コンテナに入る部分は、 until でコンテナが立ち上がるまでやってるので ERROR とかでちゃいます。このシェルを個人的にどうやって運用するのかとかはまだ考えていませんが、ひとまず iTerm2 の操作をシェルからできたので投稿です。

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4