Originally published 2017-09-18. This no longer works as of 2019-07-10, when Google removed automatic syncing between Google Photos and Google Drive. As I'm no longer using Google Photos as my primary photo storage service, I won't be developing a new solution. The information below may still be useful if you want to sync between iCloud photos and some folder on you computer.
I want to sync photos through both Google and iCloud. If you’re taking the pictures on an iOS device, this is simple - you just ensure iCloud sync is enabled and also that you’re signed in to the Google Photos app. If you’re pushing to Google Photos from another source, there’s not an obvious way to automatically sync back to iCloud. What follows is a rough way to accomplish it using a Mac as an intermediate device.
Google Photos can be configured to sync all photo/video files to a folder on Google Drive. The Google Drive app (now called Backup & Sync) can be used to ensure that syncs to a folder on the Mac. With that enabled, we just need a script to periodically check for files in the Google Drive folder that are missing from the Photos app on the Mac, then import them.
The Photos app stores all its media files in the directory
~/Pictures/Photos Library.photoslibrary/Masters/ and its subdirectories. To figure out what needs to be imported, we can compare MD5 sums of all the files there with MD5 sums of all the files in the Google Drive folder, and see which ones are missing. We can then import those files using AppleScript.
At the bottom of this post is a script to do that (it’s not actually specific to Google Photos, it can be used for importing from any folder). Update the two folder paths to be correct for your computer.
To make that script run automatically every three hours, you can put the following launchd config into
~/Library/LaunchAgents/ and then either reboot, or run:
launchctl load ~/Library/LaunchAgents/net.brokensandals.photos.sync.applefromgoogle.plist
(First make sure to update all the paths in it to be correct for your computer.)
Note: the script takes several minutes to run on my library of only three or four thousand photos. The obvious next step would be to write something that gets notified on every change to Google Photos’s folder, and keeps a persistent set of MD5 sums for files in the Photos app’s folder, so that imports can be done promptly rather than waiting for an infrequent sync.