如何判断(在脚本中)在mac os x中打开了多少个终端?

ele*_*naj 5 macos terminal

如何判断当前打开了多少终端窗口(在mac os x中)?这需要从shell脚本完成.

谢谢,

Ada*_*ark 7

此脚本执行您要求的操作,您可以使用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
Run Code Online (Sandbox Code Playgroud)

由Bavarious编辑:为了在shell脚本中使用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}")
Run Code Online (Sandbox Code Playgroud)