MacOS Extended Attributes – How to Verify if an Extended Attribute Exists

extended-attributesmacos

When running

 xattr -d com.apple.quarantine /Applications/XXX.app

sometimes I get

 xattr: /Applications/XXX.app: No such xattr: com.apple.quarantine

How does one verify if any named attribute exist for a given XXX.app?

Best Answer

The following xttar command causes both the attribute names and corresponding values to be displayed, if any exist.

xattr -l file

You can also use the ls command:

ls -@ file

That said, the ... No such xattr: com.apple.quarantine message is a non-fatal message, meaning there no real need to make it conditional, and if your goal is to remove the com.apple.quarantine extended attribute from a lot of files at once in a given directory, then cd to the target directory and use the following command:

for f in *; do xattr -dr com.apple.quarantine "$f" 2>/dev/null; done

The above one-liner will delete the com.apple.quarantine extended attribute off every file that has it and act as if the entire contents of the directory recursively were also specified (so that every file in the directory tree is acted upon), thats the -r option, while not showing errors for files that don't have the target extended attribute. (That's what the 2>/dev/null does.)