Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How can Automator or Applescript rotate 500,000 images in folders and 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

OS X Mountain Lion (10.8)

Posted on Dec 1, 2012 5:42 AM

Reply
31 replies

Dec 3, 2012 3:15 AM in response to twtwtw

twtwtw wrote:


Oooo, good point. It would probably be ok since it's reusing the same openedFile variable (that should automatically release the last image data), but to be on the safe side ludwip could replace the save line with the following:



closesavingyes

that would definitely avoid any such problems. He might even want to add the following lines to the on error section:


try

closeopenedFilesavingno

end try

which will try to close any opened image in the event of an error.


Thanks twtwtw,


Just to stay on the safe side.

Does the code supposed to look like this?


Thanks a lot for your input.


set folderToProcess to choose folder with prompt "Choose a folder to process"

set folderPath to quoted form of POSIX path of folderToProcess


-- 13 is a spotlight constant for images that I can't find documented anywhere (I got it by saving a spotlight image search in the Finder and examining it in a text editor). FYI.

set fileList to paragraphs of (do shell script "mdfind -onlyin " & folderPath & " '_kMDItemGroupId == 13'")


tell application "Image Events"


-- tell image event not to quit itself

set quit delay to 0


repeat with thisImageFile in fileList

try


-- open the image file

set openedFile to openthisImageFile


tell openedFile


-- you didn't specify which way or how much you wanted to rotate. this rotates them 90° clockwise


rotateto angle 90


-- save back to same file


closesavingyes

end tell

on error errstr


-- image events had an error - dislpay alert, then skip this file

my displayError(thisImageFile, errstr)

try


closeopenedFilesavingno

end try

end try

end repeat



-- reset Image Event's automatic quitting

set quit delay to 900

end tell


on displayError(thisImageFile, errstr)

tell application "System Events"

display alert "Image Events Error" message "file : " & thisImageFile & return & return & "error: " & errstr

end tell

set imageAlias to POSIX filethisImageFile

tell application "Finder"

set label index of item imageAlias to 1

end tell

end displayError

Dec 3, 2012 1:04 PM in response to ludwip

well, I just ran it on a copy of my entire pictures folder from the script editor and it worked fine. You didn't mention you wanted to run this from an app, and I suspect any app you run it from is going to look like it's frozen - applescript isn't threaded, so it will just chug away unresponsively until it's done, which may take a while.


if you want to be sure it's working and not frozen, you can add some audio feedback. set i to 0 before the repeat loop, then add in a vocal counter before the end repeat statement.


set i to 0

repeat with thisImageFile in fileList


-- yaddayaddayadda


set i to i + 1

if (i mod 300) = 0 then

say (((i * 1000) div (count of fileList)) / 10 & " percent done") as text

end if

end repeat

Dec 4, 2012 7:09 AM in response to twtwtw

Thanks twtwtw,


Just to let you know, I don't run script in any other application than AppleScript Editor.


It is working almost perfect now.


The only problem that I've experienced is related to an error message. If I don't dismiss the message on time it will finish script before images are rotated. Is there any chance for the script just to ignore this kind of errors?


Thanks

Dec 4, 2012 11:00 AM in response to VikingOSX

Hi VikingOSX,


I was trying to use the script, but I must be doing something wrong in the terminal I guess.


Should there be any dialog box or anything else where I set folder for the script to work?


Thanks

VikingOSX wrote:


Thanks for your imput.

However there are two scipts in your post.

This one: '

chmod +x rotate.sh

./rotate.sh'

as well as former (longer one). Which one should I use?



There are two distinct commands to run in the terminal. You do both, on separate command lines as shown. The assumption is that you are currently in your home login directory. Again, I would advise running this on a few files, then stop, and analyze the files to ensure you are satisfied. Then apply it to a larger subset, and review. Then to all images you wish to rotate.


  1. chmod +x rotate.sh
    1. Use the chmod OS X command to change the script permissions to executable
    2. This does not run the script or alter contents.
  2. ./rotate.sh
    1. Start the rotate.sh script
    2. The script will prompt you for the directory path to the main image folder where you wish to begin
      1. If on an externally mounted drive, then /Volumes/drivename/path-to-image-folder
      2. This script does not use restricted system syntax to operate on your image files, as it expects that their access privileges are already owned by your login name.

Dec 4, 2012 11:09 AM in response to ludwip

sips handles only the following formats (from its man page):


jpeg | tiff | png | gif | jp2 | pict | bmp | qtif | psd | sgi | tga


if you feed it the wrong kind of file it will throw an error, any I've never understood xargs well enough to know what it will do if the utility it's running throws an error.


THe find command he's using will find every file that happens to have an extension; are their any other types of files in that directory?

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

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.