如何知道(在脚本中)mac os x中打开了多少个终端? [英] How can I tell (in script) how many Terminals are open in mac os x?

查看:79
本文介绍了如何知道(在脚本中)mac os x中打开了多少个终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么知道当前打开了多少个终端窗口(在Mac OS X中)? 这需要通过shell脚本来完成.

how can I tell how many Terminal windows (in mac os x) are currently opened? this needs to be done from a shell script.

谢谢

推荐答案

此脚本可以满足您的要求,您可以使用osascript从cmd行运行它.

This script does what you ask for, you use osascript to run it from the cmd line.

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,您可以执行以下操作:


Edit by Bavarious: In order to use Adam’s AppleScript inside a shell script, you can do the following:

#!/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}")

这篇关于如何知道(在脚本中)mac os x中打开了多少个终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆