0

I would like to start a tmux session on a separate window in iTerm2. Now I'm writing my own configuration script to launch the session.

tmux new-session -s dev -n main -d
tmux send-keys -t dev "cd $DL" C-m
tmux split-window -h -t dev
tmux split-window -v -t dev -p 30
tmux resize-pane -x 70 -y 20
tmux attach -t dev

This starts a new session but the window is on the window I execute the script, not the new, separate window in iTerm2.

So I changed the first line (tmux new-session -s dev -n main -d) to tmux -CC new -t dev, but then although the session starts in a new window, it does not have the split and the resize. It seems to only open the new session in a new window and that's all.

How can I make it launched in a new window with all the initial settings including the directory change, split window, etc...?

0

You can use applescript to do something like this:

$ cat a.bash
#!/bin/bash
osascript - "$@" <<EOF
on run argv
tell application "iTerm"
    activate
    set new_term to (create window with default profile)
    tell new_term
        tell the current session
            repeat with arg in argv
               write text arg
            end repeat
        end tell
    end tell
end tell
end run
EOF

This provides a script which can then pass arguments passed into it, into another iterm2 terminal.

For example:

$ ./a.bash "echo 'hello iterm2'"

   ss of iterm2 launch

References

  • Thanks but how can I take the script to the argument of the a.bash? ./a.bash < my_script does not work (it only launches the window). It works if it is ./a.bash "tmux new -s dev", though. – Blaszard Jul 5 '18 at 11:26
  • @Blaszard - can you please update your question, it's not clear what exactly you want/expect to happen here then.If the last part works I'd saw your problem's solved, which I know isn't the case in your mind, but we need more to go on then. – slm Jul 5 '18 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.