Last active
July 31, 2016 20:18
-
-
Save richardtallent/ace307a40e09422c910b01dcea049576 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The intent of this script is to search for photos you've tagged and create optimized versions | |
# of them in a particular folder (with subfolders for each tag). You can then set iTunes to sync | |
# your phone's Photos app to this folder, allowing you to easily carry around some albums | |
# (separate from your camera roll, Photostream, or other cloud folders). I created this as a way | |
# to ensure that both my phone and my wife's have consistent, offline copies of our favorite family | |
# photos. We use different Mac computers but have a shared drive with family photos, so I needed a | |
# solution that allows either of us to flag photos. Once set up, adding photos to your phone is as | |
# simple as adding a tag to the photo in Finder and re-running the script (which can be set to run | |
# periodically). | |
# | |
# This could also be useful if you have a non-Apple device (phone, tablet, digital picture frame, | |
# web site, etc.) that you want to synchronize with some favorite photos. | |
# This script does the following: | |
# -- Searches for files in SOURCEPATH with particular Tags using Spotlight (mdfind) | |
# -- Copies them to DESTPATH into subfolders named for each Tag | |
# -- Resizes the photos down (sips) for phone display | |
# It does not currently: | |
# -- Remove files no longer bearing a particular tag | |
# -- Overwrite photos already copied (for performance) | |
# -- Have any special consideration for sidecar files (AAE, etc.) | |
# Version: 2016-07-31 | |
# License: MIT | |
# Requirements: OS X | |
# Author: Richard Tallent, www.tallent.us | |
# Comments and suggestions welcome. | |
# List of tags to look for. "Double Quote" any that contain spaces | |
tags=( Family Friends House ) | |
# Full path to your family photos, with the trailing "/" | |
sourcepath="/Volumes/foo/Family Photos/" | |
# Full path of the folder you want to sync to your device (in iTunes, etc.), with trailing "/" | |
destpath="/Volumes/foo/iPhone Sync Photos/" | |
# Loop through tags | |
for tag in "${tags[@]}" | |
do | |
favorites=$(mdfind -onlyin "$sourcepath" tag:$tag) | |
destfolder="$destpath$tag/" | |
mkdir -p "${destfolder}" | |
echo "Syncing to ${destfolder}" | |
while IFS= read -r favorite | |
do | |
echo "copying ${favorite} to ${destfolder}" | |
cp -n "${favorite}" "${destfolder}" | |
done <<< "$favorites" | |
echo "Shrinking photos in ${destfolder}" | |
sips -Z 2000 "${destfolder}"*.jpg | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment