如何解决如何知道在脚本中mac os x中打开了多少个终端?
| 我如何知道当前打开了多少个终端窗口(在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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。