What is a reasonable way for a script that runs otool to handle the need to agree to a new license?

I run otool from a script (actually from a program) and find it annoying that otool fails if I need to agree to a new version of the Xcode and SDKs license. Is there a way to test ahead of time whether this will happen, or detect when this problem occurs, so that I can display a dialog to tell me what I need to do?

This happened after upgrading from macOS Tahoe beta 1 to beta 3.

sudo xcodebuild -license

run it in an empty directory so it doesn't actually build anything. More info in the man page for xcodebuild.

What is a reasonable way for a script that runs otool to handle the need to agree to a new license?
 
 
Q