prezto/modules/osx/functions/wherefrom
Josh Heidebrecht b0c0c6cc58 Add wherefrom and settings function for osx
- Fix a missing local variable definition in tab
2015-12-24 00:43:14 -07:00

39 lines
767 B
Text

#
# Tells Finder where a file was downloaded from
#
# List of spotlight metadata keys https://developer.apple.com/library/mac/#docum
#
# Authors:
# josho
#
local url
local success
if (( $# < 2 )); then
cat >&2 <<EOF
Usage: $0 <url> [file ...]
EOF
return 1
fi
url=$1
shift
while (( $# > 0 )); do
if [[ -f "$1" ]]; then
# A json plist containing the Downloaded from URL
local plist='["'"$url"'"]'
# Convert to a hexdump representation of a binary plist
# In xxd set the max column count to avoid line breaks
local binplist=`echo -n "$plist" | plutil -convert binary1 -o - - | xxd -p -c 256`
xattr -wx 'com.apple.metadata:kMDItemWhereFroms' "$binplist" "$1"
else
print "$0: cannot read: $1" >&2
success=1
fi
shift
done