macOS: X cannot be opened because the developer cannot be verified

macOS: X cannot be opened because the developer cannot be verified

Lately I was installing the embedded ARM toolchain to compile some STM32 code, and I ran into this beautiful error:

If you are a macOS user it's very probable that you have already seen this message, and most likely you already know the workaround (which is right-click on the executable and choose Open by the way).

However, if you need to do that for many binaries, it can become frustrating or unfeasible - which is exactly the case for a build toolchain that contains many commands like ld, objcopy, gcc, cpp, strings, g++ and many more. Investigating a bit, it all boils down to removing the com.apple.quarantine extended attribute that browsers stick to executables, so you can use find to remove it from all executables within a directory:

find ~/gcc-arm-none-eabi -type f -perm +111 -print0 | xargs -0 -n 20 -- xattr -d com.apple.quarantine