Question

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?

Was it helpful?

Solution

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.)

OTHER TIPS

There is no direct way to test the existance of a specific extended attribute. In your case you could, with

file=/path/to/file
attr=attribute

do something like

if [[ $(xattr "$file") = *$attr* ]]; then
    xattr -d $attr "$file"
fi

or, as a one-liner

[[ $(xattr "$file") = *$attr* ]] && xattr -d $attr "$file"
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top