How can Automator or Applescript rotate 500,000 images in subfolders

Hi Everyone,
I have very specific question.
I’ve got 500,000 images that sit in 98 subfolders. Some of the subfolders contain 25,000 images.
Now my question: is there any script/automator workflow that I can use?
I was trying to create a workflow:

  1. Ask for Finder Items
  2. Get Folder Contents (tick repeat for each subfolder found)
  3. Rotate images
    It works OK, but only for these folders where there is less than 4,096 files:
    I normally receive following error message:
    ‘Rotate images failed - 1 error
    too many arguments (12019) – limit is 4096’
    Is there any way to increase this limit or create completely different apple script?
    I really hope that someone will help me with this one.
    By the way my OS is Mountain Lion
    Thank you

I have no idea if AppleScript has a limit on how many items it can iterate through, but I am confident there would be plenty of workarounds if a problem arose.

Are you looking to replace the original image file with the rotated image file, or create an entire set of new images with the rotation?


There are many ways to Rome! In your case, obtaining a list of all your imagefiles first, and then extracting say 4094 at a time, would a path to follow. This would include some extra steps, but solve your problem.

Usually AppleScript has a limit of 12^14 = 16384 items, so I find your limit puzzling! :slight_smile:

You can find most of the pieces you need around here, when it comes to searching and such. You can get the first 4094 items with somethinling like.

set curList to ( do shell script" sed -en -i 'bak' '1,4094 p' filelist.txt -e '1,4094 d'")


Did you try with the Folder Actions? There is already a script that rotate images using image events.

set mainFolder to "/Users/ludwip/Documents/My Folder"
do shell script "find " & quoted form of mainFolder & " -iname *.jp*g -o -iname *.pdf -o -iname *.tiff -print0 | xargs -0 sips -r 90"