There seems to be a pretty major bug here. I tried to run it and it told me it was going to clear the wrong disk. I looked at the code a little closer and it seems like you opted to continue looking for additional disks that were ready to be cleared instead of breaking out of the loop. Unfortunately, this means that if only one disk is found ready to be cleared, it will think it's the last one in the array since the previously identified disk isn't remembered. I "fixed" this by adding a break command at line 113 (after the "((found++))" command). Oddly, the script still didn't work for me even though it identified the correct device. I get an EOF error right when it is about to unmount the drive. I didn't see any errors in the code to cause this, so I'm wondering if it's a copy-and-paste issue or something. I've attached my log in case it's helpful. For reference, disk7 is the one I was trying to clear and disk8 is the one it incorrectly tried to clear first.
I don't need the script anymore as I just created my own script with the 2 action lines, but wanted to make sure I reported this issue so that no one accidentally clears the wrong drive.
clear_array_drive_error.txt