Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
Last active January 5, 2018 09:17
Show Gist options
  • Save maxpeterson/be7ab0b754413dc3b22188fda1c0cb6a to your computer and use it in GitHub Desktop.
Save maxpeterson/be7ab0b754413dc3b22188fda1c0cb6a to your computer and use it in GitHub Desktop.
Copy music folders based on OSX tag
#!/bin/bash
colour=$1; shift
if test "$colour" == "" ; then
echo "Please provide a colour / tag name to search for."
exit 1
fi
destination=$1; shift
if test "$folder" == "" ; then
echo "Please provide a destination folder to copy files to."
exit 1
fi
directory=$1; shift
if test "$directory" == "" ; then
echo "Please provide a directory to search in."
exit 1
fi
mdfind -onlyin "$directory" "kMDItemUserTags == '*$colour*'" | while read src; do
folder=$(basename "$src")
dst="${src/#$directory/$destination}"
# map the src
#src="${src/#$directory/\/Volumes\/M\/Encoded\/}"
rsync -auv "$src" "$dst"
done
@maxpeterson
Copy link
Author

Copy all files and folders tagged 'Purple' in /Volumes/DIRECTORY to /Volumes/DESTINATION/

osx-copy-by-tag.sh Purple /Volumes/DESTINATION/ /Volumes/DIRECTORY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment