问题描述
|
我如何知道当前打开了多少个终端窗口(在Mac OS X中)?
这需要通过shell脚本来完成。
谢谢,
解决方法
该脚本可以满足您的要求,您可以使用
osascript
从cmd行运行它。
tell application \"Terminal\"
set c to 0
repeat with i from 1 to (count of windows)
set c to c + (count of tabs in window i)
end repeat
c
end tell
由Bavarious编辑:为了在外壳程序脚本中使用Adam的AppleScript,可以执行以下操作:
#!/bin/bash
read -d \'\' OSASCRIPT << EOF
tell application \"Terminal\"
set c to 0
repeat with i from 1 to (count of windows)
set c to c + (count of tabs in window i)
end repeat
c
end tell
EOF
nwindows=$(osascript -e \"${OSASCRIPT}\")
, cnt=$(w -h | grep \"^$(whoami) *s[^ ]* *-\"|wc -l)
echo Your current terminal sessions: $cnt