How do I hide Terminal windows using AppleScript?

I am using an AppleScript where I need to open many Terminal Windows using:

repeat while counter > windowAmount
    tell application Terminal
       do script ""
    end tell
end repeat

Is there any way that I can hide the new Terminal windows that are opening up? I am fine with it appearing in the dock but I don't want it to show any windows.


You could minimize each window as it's created, although you'll see each window as it minimizes to the Dock, or you could hide each window as it's created. The latter of which would require additional code as some point to unhide the window.

To minimize the window:

tell application "Terminal"
    do script ""
    set miniaturized of window 1 to true
end tell

To hide the window:

tell application "Terminal"
    do script ""
    set visible of window 1 to false
end tell

To uhide the window:

tell application "Terminal" to set visible of every window to true