[英]Open multiple terminal windows mac using bash script
#!/bin/bash
#!/usr/bin/python
read -p "Execute script:(y/n) " response
if [ "$response" = "y" ]; then
echo -e "\n\nLoading....\n\n"
for ((x = 0; x<5; x++))
do
echo -e "Open $x terminal\n\n"
open -a Terminal.app
done
fi
这只会打开一个新的终端窗口。 如何打开10个新的终端窗口?
如果要从bash脚本(或从命令行)打开10个新的终端窗口,请使用以下命令:
osascript -e 'tell application "Terminal"' -e 'repeat 10 times' -e 'do script ""' -e 'end repeat' -e 'end tell'
或集成到您现有的代码中,尽管已重新编码:
#!/bin/bash
shopt -s nocasematch
read -p " Execute script? (y/n): " response
if [[ $response == y ]]; then
printf " Loading....\\n"
for ((x = 0; x<10; x++)); do
printf " Open %s Terminal\\n" $x
osascript -e 'tell application "Terminal" to do script ""' >/dev/null
done
fi
shopt -u nocasematch
其输出为:
$ ./codetest
Execute script? (y/n): y
Loading....
Open 0 Terminal
Open 1 Terminal
Open 2 Terminal
Open 3 Terminal
Open 4 Terminal
Open 5 Terminal
Open 6 Terminal
Open 7 Terminal
Open 8 Terminal
Open 9 Terminal
$
假设您尚未设置在选项卡中打开新窗口,则会显示10个新的终端窗口。
您需要将-n选项赋予open命令
-n
打开一个新的应用程序实例,即使该实例已经在运行。
for ((x = 0; x<5; x++)) do
echo -e "Open $x terminal\n\n"
open -na Terminal.app
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.