如何知道在脚本中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
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...