Skip to content

Instantly share code, notes, and snippets.

@jerrykrinock
Last active January 6, 2019 00:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerrykrinock/d5a8606228e2df281450 to your computer and use it in GitHub Desktop.
Save jerrykrinock/d5a8606228e2df281450 to your computer and use it in GitHub Desktop.
CheckAndClearXattrs.sh checks a given target directory for extended attributes. If any extended attributes are found, it removes them and displays a dialog. Otherwise, it just logs to the system console. You provide the target directory's path as the first and only argument to this script. I launchd it once an hour, using the file, CheckBuildDir…
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>CheckBuildDirXattrs</string>
<key>ProgramArguments</key>
<array>
<string>/Users/jk/bin/CheckAndClearXattrs.sh</string>
<string>/Users/jk/Documents/Programming/Builds</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>24</integer>
</dict>
</dict>
</plist>
#!/bin/bash
# This script checks a given target directory for extended attributes. If any extended attributes are found, it removes them and displays a dialog. Otherwise, it just logs to the system console. You provide the target directory's path as the first and only argument to this script.
# You typically schedule this script to run periodically, with a launchd agent or cron job. I launchd it once an hour.
TARGET=$1
TARGET_NAME=`basename $TARGET`
TARGET_PARENT=`dirname $TARGET`
cd "$TARGET_PARENT"
ATTRS_BEFORE=`xattr -l "$TARGET_NAME"`
if [ "$ATTRS_BEFORE" != "" ]; then
TITLE="Warning from $0"
xattr -c "$TARGET_NAME"
ATTRS_AFTER=`xattr -l "$TARGET_NAME"`
osascript -e "display dialog \"On this directory:\" & return & \"$TARGET\" & return & return & \"The following undesired xattrs were found:\" & return & \"$ATTRS_BEFORE\" & return & return & \"This script has attempted to remove those xattrs. After removing, the xattrs are:\" & return & \"$ATTRS_AFTER\" with title \"$TITLE\""
logger $0 found xattrs: $ATTRS_BEFORE on $TARGET. After removing, xattrs are: $ATTRS_AFTER
else
logger "$0 found 0 xattrs (good!) on $TARGET"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment