1

I use MS OneDrive to sync photos taken on my Android phone to my Mac (they are synced to ~/OneDrive/Photos/Camera Roll). I would like to move the synced files into folders organised by Year and Month (Year/Month) that the photo was taken (or simply the file creation date).

Ideally this process would run whenever new photos are added to the Camera Roll folder.

I took a look at Automator Folder Actions, but it seems limited to only doing the exact same thing to everything that gets added to the folder (e.g. move all new items into a specific folder).

I found a PowerShell script that does exactly this in Windows, but haven't found any corresponding scripts or free apps that do this in macos.

Any suggestions?

4
  • Folder Actions will run any script on the file. There's nothing stopping the script from moving to a folder name based on the Date stamp (or, better: the EXIF data). Of course, if you imported the photos into Photos.app, then it would sort them automatically. Same is true for Lightroom or other photo management apps. I presume the phone isn't an iPhone?
    – benwiggy
    Jun 23, 2021 at 11:40
  • bash or zsh can be easily scripted for this, see apple.stackexchange.com/questions/282270/… for a slightly different example.
    – nohillside
    Jun 23, 2021 at 11:40
  • Yes - it's an Android. I used Lightroom for many years, and this functionality was available. I dropped Lightroom when Adobe switched to subscription model, and moved to using On1 Raw, which doesn't have file management features (it works with the files as they are organised in Finder). Thanks for the pointer on scripting. The example is somewhat different - reorganising existing folders that already named for the full date. Maybe it will be useful, but hopeful someone else has already figured this out and willing to share what they learnt.
    – dunxd
    Jun 23, 2021 at 12:01
  • <shrug> Use Hazel. noodlesoft.com Jun 23, 2021 at 14:50

3 Answers 3

3

I found Organize - an open source and free of charge command line tool designed to do exactly this sort of thing.

The following config does the trick:

rules:
  # Move photos into Year/Month folders in My Photos
  - folders: ~/OneDrive/Pictures/Camera Roll
    filters:
    - extension: jpg
    - created
    actions:
     - move: ~/Pictures/My Photos/{created.year}/{created.month:02}/

I then created an Automator Folder Action that will Run a Shell Script anytime a file is added to the OneDrive Camera Roll:

/usr/local/bin/organize run --config-file=~/OneDrivePhotoSync.yaml
3
  • 1
    Geez, talk about swatting flies with a sledgehammer! Having to set up YAML config files? Specifying extensions in advance? All just to organize a folder of files into subfolders by date? I think I could set up the folders and mover the files by hand faster than learning how to configure this thing.
    – John Smith
    Jan 3 at 0:08
  • Oh, wait, it gets even better: the response when I try to install this thing is ERROR: Command errored out with exit status 1: /usr/local/opt/[email protected]/bin/python3.9 /usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /var/folders/hw/zhqx4wvs2z996ncrw1g153j00000gq/T/tmp0x3_ey_j Check the logs for full command output. Ugh, no thanks! How has nobody on the entire internet written a simple, working Applescript or BASH script that does this without requiring a software engineering degree to run it?
    – John Smith
    Jan 3 at 0:10
  • Found a GUI app that does it without any headaches, see my answer below.
    – John Smith
    Jan 3 at 0:19
1

You could use the folder actions to run a bash script like this:

#!/bin/bash

DIR="/Users/USERNAME/OneDrive/Photos/Camera Roll"
target=$DIR
cd "$DIR" || exit

for file in *; do
    # Top year folder name
    year=$(stat -c "%y" "$file" | awk '{print substr($0,0,4)}')
    # Secondary folder name
    subfolderName=$(stat -c "%y" "$file" | awk '{print substr($0,6,2)}')

    if [ ! -d "$target/$year" ]; then
        mkdir "$target/$year"
        echo "starting new year: $year"
    fi
    if [ ! -d "$target/$year/$subfolderName" ]; then
        mkdir "$target/$year/$subfolderName"
        echo "starting new day & month folder: $subfolderName"
    fi
    echo "moving file $file"
    mv "$file" "$target/$year/$subfolderName"

done

You can also modify the directory names to include the day or the year and the month by changing the selected substring in the substr command.

0
0

As of this date, found an old (OS X 10.8) but very simple and straightforward donationware GUI app that does it and is still available, and at least still opens on everything at least up through Monterey: DateTree (https://www.orange-carb.org/DateTree/downloads.html). Right now I have it running on a folder of about 10,000 files on my old El Cap machine and it's fairly slow but seems to be working exactly as advertised. No configuration needed, no muss, no fuss. I might send the author a little donation.

It does copy the files, not move them, but that's not a problem, I can delete the source folder afterwards. It also can use dates embedded in EXIF data, if you need that, although I don't. And it functions as a droplet... if you just drop a folder of files on it it'll remember the default settings from last time.

It even gives you a window reporting the copy results, although you have to look in the menus to see it's there, it's not obvious.

Not too shabby, I think.

I have no association with DateTree, just found it while searching because I'm having this same problem and don't want to mess with a bunch of hinky python, ruby, broken installers and strange errors, etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .