4

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?

0

2 Answers 2

5

The following xattr 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's 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 this 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.)

1
  • I dunno about the non-fatal error. When I run xattr from the command prompt (bash), I get the message about "No such xattr", and, importantly for the context in which I'm working, the exit code is 1 (as displayed by echo $? immediately following). xattr is being executed in a series of commands (by make) and if the exit status for any command is not 0 (0 being the conventional "OK" exit status), the whole thing stops. So it would be ideal to avoid executing xattr -d if it's not needed. For the record I'm working on macOS Catalina. Commented Sep 29, 2021 at 22:09
1

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"
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .