Aqui está o script que funciona:
#!/bin/bash
osascript -e 'display notification "Checking USB" with title "USB Notification"'
for disk in $(diskutil list | awk '/disk[1-9]s/{ print $NF }' | grep -v /dev); do
if [[ $(diskutil info $disk | awk '/Protocol/{ print $2 }') == "USB" ]]; then
echo "Device $disk is a USB removable disk"
diskName=$(diskutil info $disk | awk -F"/" '/Mount Point/{ print $NF }')
if [[ $(diskutil apfs list ${disk:0:5} | awk '/FileVault/{ print $2 }') == "No" ]]; then
osascript -e 'display notification "Detected a USB removable disk that is not encrypted, ejecting" with title "USB Notification"'
echo "Unmounting ${disk:0:5}"
diskutil unmountDisk ${disk:0:5}
fi
fi
done