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?

  • 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 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 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 at 12:01
  • <shrug> Use Hazel. noodlesoft.com Jun 23 at 14:50

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


DIR="/Users/USERNAME/OneDrive/Photos/Camera Roll"
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"
    if [ ! -d "$target/$year/$subfolderName" ]; then
        mkdir "$target/$year/$subfolderName"
        echo "starting new day & month folder: $subfolderName"
    echo "moving file $file"
    mv "$file" "$target/$year/$subfolderName"


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.


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:

  # Move photos into Year/Month folders in My Photos
  - folders: ~/OneDrive/Pictures/Camera Roll
    - extension: jpg
    - created
     - 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

You must log in to answer this question.

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