且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-08 19:46:28

此脚本可以满足您的要求,您可以使用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}")