Categories
Uncategorized

Using Automator to add Dropbox camera uploads to Photos on a Mac

Why Script Importing into Photos?

Recently, Apple deprecated iPhoto on the Mac in favor of a new iPhoto-like app called Photos. The nice thing about iPhoto was that you could drag a bunch of photos onto the iPhoto icon, and those photos would automatically import as a new album. I've found a bit of bugginess with Photos (perhaps it will be fixed in newer versions). Sometimes dragging photos into the app won't do anything. Sometimes it will launch up a preview and then ask to import. Other times it will just import.

I use Dropbox's camera upload function to have the pictures from my Android phone automatically upload to Dropbox's servers and then down to my Mac.

The Automator Script

I made an Automator .app with a Run AppleScript action that runs the following script (substitute in your own path and username to whatever folder you want to import):

set importFolder to POSIX file "/Users/yourusername/Dropbox/Camera Uploads/" as alias

set extensionsList to {"jpg", "png", "tiff"}
tell application "Finder" to set theFiles to every file of importFolder whose name extension is in extensionsList

set timeNow to time string of (current date)
set today to date string of (current date)
set albumName to today & " " & timeNow
set imageList to {}
repeat with i from 1 to number of items in theFiles
set this_item to item i of theFiles as alias
set the end of imageList to this_item
end repeat

tell application "Photos"
activate
delay 10
import imageList into (make new album named albumName) skip check duplicates no end tell

tell application "Finder"
delete imageList
end tell

Acknowledgements

The basis for this script (with my own tweaks, of course) is how to easily import images into new Photos.app.

Tweaks in This Script

The main differences in my version of the script are:

  • Specification of the folder ahead of time instead of a prompt for the user to choose a folder
  • No check that there are images in the folder (Photos itself will tell you there's nothing to import if the Dropbox folder is empty).
  • Album name is based only on the date and time instead of prompting for a name and then appending a date and time.
  • Waiting longer after launching ("activat[ing]") Photos before doing the import. I found (on my non-SSD hard drive) that 2 seconds would make the Automator .app crash before importing.
  • Deleting (moving to the Trash, actually) the imported folders when done.