0

I'm running under Big Sur (macOS 11.6). I have a shell script which launches a Finder window to a certain directory as follows:

/usr/bin/open /path/to/directory

After the shell script opens this Finder window in that manner, I'd like that shell script to wait while periodically polling for the existence of that Finder window. Once that particular Finder window gets closed, I'd then like my shell script to stop waiting and continue processing.

Is there a way to do this in macOS 11.6?

Thank you very much in advance.

1 Answer 1

1

I figured out how to solve this.

I repeatedly run the following command in my shell script in a loop, with a short sleep between loop iterations:

/usr/bin/osascript -e 'tell application "Finder" to get the name of every window' | grep '/path/to/directory'

As soon as it stops finding a match, I break out of the loop, since it means that the Finder window for /path/to/directory has closed.

You must log in to answer this question.

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