Improved OS X Clear Quarantine Flag Script
Developer
— 12 Jun 2009 12:52 — 967 days ago
I have written about clearing Apple’s Internet download quarantine flag from files to get rid of the security warning before.
Recently Apple pushed Xcode documentation updates frequently, and I somtimes had to clear the flag from other HTML files all over the harddisk, not just in /Developer. The old way was just too slow for frequently changing and/or big sets of files:
find /Developer -type f -name '*.html' \
-exec sh -c 'xattr "$0" | grep -q quarantine && xattr -d com.apple.quarantine "$0"' {} \; -print
This spawns lots of subprocesses and it turns out that xattr is not a native binary but a Python script, which means that the Python interpreter is fired up twice for each file.
It takes ages this way so I rewrote it to loop in Python and use Python’s native xattr module:
#!/bin/bash
#
# Remove the quarantine extended attribute from all
# developer documentation HTML files to get rid
# of the "downloaded from the Internet" warning
#
# Marc Liyanage / www.entropy.ch
#
[ $UID -eq 0 ] || { echo $0 must be run as root; exit 1; }
find /Developer -type f -name '*.html' | python <(cat - <<EOF
#!/usr/bin/env python
from xattr import *
import sys
import string
attr = 'com.apple.quarantine'
for file in sys.stdin:
file = string.rstrip(file, "\n")
if (attr in listxattr(file)):
removexattr(file, attr)
EOF
)
This is a lot faster.
|


