How can I open multiple tabs automatically on terminal in mac os Lion by executing some commands on each tab?

自闭症网瘾萝莉.ら 提交于 2020-06-12 12:20:19

问题


I need to automatically open terminal with multiple tabs and need to execute multiple commands on it.

I know how to do it in ubuntu. but its not working on mac os . Any Idea?

gnome-terminal --tab -e "tail -f somefile" --tab -e "some_other_command"

回答1:


I can give you a clue.

Using osascript, you can do it.

UPDATE:

One thing you need to understand is, gnome-terminal is for Linux. Gnome is a very popular Desktop environment written for Linux.

Use this oneliner for opening a new tab with $PWD as the working directory:

osascript -e "tell application \"Terminal\"" -e "tell application \"System Events\" to keystroke \"t\" using {command down}" -e "do script \"cd $PWD; clear\" in front window" -e "end tell" > /dev/null

Following one liner will just open a new tab with $PWD as working directory and will execute echo Hi

osascript -e "tell application \"Terminal\"" -e "tell application \"System Events\" to keystroke \"t\" using {command down}" -e "do script \"cd $PWD; echo HI\" in front window" -e "end tell" > /dev/null


来源:https://stackoverflow.com/questions/14679809/how-can-i-open-multiple-tabs-automatically-on-terminal-in-mac-os-lion-by-executi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!