1

How can I include in a (zsh) shell script a command that will minimize one particular window among several windows open in a specified app?

I already know how to include a command that opens an app with one or more documents open in it, e.g.:

open -a textedit.app .profile .zshrc

What command can I use from Terminal to minimize a specified one of those just-opened windows?

I presume that something involving osascript is involved, such as in Is there a way to minimize open windows from the command line in OS X Lion?. But the method given there in the Edit by the original poster: (i) minimizes all the windows; and (ii) does use osascript which, as I recall, is not so simple to call from within a shell script.

0
1

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.

0

How can I include in a (zsh) shell script a command that will minimize one particular window among several windows open in a specified app?

Use osascript to execute the following example command:

osascript -e 'tell application "TextEdit" to set miniaturized of every window whose name is "Untitled" to true'

Obviously, change the name of the application and the name of the window as needed.

Not the answer you're looking for? Browse other questions tagged .