Command in shell script to minimize particular window of an open app? [duplicate]

You referenced this page, which is only one example but a decent starting point. (You might also try more general search terms, such as “AppleScript window management”.)

  • In most Applications, each window has an ‘index’ property that one can use to determine, for example, which is frontmost or which was created first. Depending on the complexity of the AppleScript dictionary for that particular application, it should often be possible to act on windows based on other properties, such as title.

  • To minimize multiple (or all) windows, one could run a loop that queries the ‘id’ or ‘index’ and ‘visible’ status of every window, and then act on them as desired. (I have done this in the past with web browsers to iterate through every window and tab for the purposes of exporting and logging.)

  • As far as running ‘osascript’, invoking it from a shell script file will let you call it using whatever shell (e.g. sh, bash, maybe even osascript itself) that makes quoting the easiest (or whatever shell the example you are copying was written for), even if you are using Zsh as your interactive (user) shell.

Regardless, I strongly recommend getting your AppleScript working first in AppleScript Editor before attempting to run it from a terminal shell.