Unofficial archive. This is a read-only, community-run archive of the Apple Support Community. It is not affiliated with or endorsed by Apple Inc.

Automator script using ivfolder.rb / ExifTool fails to sort image files into folders by date

I have used this Automator script to sort (image) files into folders by date (from EXIF data) written by forum user VikingOSX for years. Suddenly it gives me this error:



What may be the problem?


I have reinstalled ExifTool and restarted my computer.

16 replies

OK, so I tried removing the files I was trying to process (about 900 files) from the folder in question and then adding back and processing a few at a time. Turns out the script worked with all files but two. Perhaps those files are corrupt and that's the whole problem?

Does EXIFTool show any of the fields used in the Ruby script for those JPGs? Perhaps some EXIF metadata is missing.

The Ruby script is attempting to pass an empty create_date string into the FileUtils.mkdir function and that being taboo, blows up the script. Something is amiss in the code that is not obtaining the creation_date, whether ExifTool, or pure Ruby. Stay tuned as I am testing it with your IMG_8213.JPG image.

The files are missing DateTimeOriginal and maybe more.

Ok, I managed to process your preceding image and created a folder for it. This required some thought about:


  1. What ExifTool returns as a string when using multiple date arguments and how those arguments behave individually when they find no date string. They embed empty strings ("\n\n") in the return string.
  2. Taking the min of a string that contains an empty string element will return nothing, and that was the cause of the FileUtils.mkdir(filename…) blowing up. It cannot take an empty argument.


So here is the revised Ruby script.



No help will be forthcoming without seeing the Ruby script and the Automator workflow to test in a current version of EXIFTool and Golden Gate. Apple has hardly updated Ruby v2.6 in years…

No help will be forthcoming without seeing the Ruby script and the Automator workflow to test in a current version of EXIFTool and Golden Gate. Apple has hardly updated Ruby v2.6 in years…


Both FileUtils.mkdir and FileUtils.mkdir_p work with the System Ruby v2.6.10.p210 in macOS 27.0.1. The first makes a single directory and the second makes interim folder hierarchy with this syntax:


#!/usr/bin/ruby

require 'fileutils'

singleFolder = File.expand_path('~/Desktop/Foo')
hierFolder = File.expand_path('~/Desktop/Bar/Baz/Foo')

FileUtils.mkdir singleFolder
FileUtils.mkdir_p hierFolder


Do those two unprocessed files have extensions that are omitted in that Ruby extensions set? Can you open those two martian files in Apple's Preview or Quick Look?

I replaced your first action in your Automator application:



With:



No Ruby code was changed. When I ran this updated Automator application, aimed it at a folder on my Desktop containing five random image picks, it generated the following folder results without any error:




Tested: macOS 27.0.1, M4 Mac Mini Pro.

They are .JPG and yes they can be opened by Apple's Preview or Quick Look. Both of them were edited with the iPhone app SimplyBW, but I'm sure there were more of that kind in the batch ...


Anyway, seems like your script was not to blame :-)

If for some reason, ExifTool returns no date string from the image file, the script will still return the birthtime (Finder creation date) of the image. If there are multiple date strings found by ExifTool, then the first one will be used. I don't see how this script would fail to get some date from a given image file, if not in the image metadata.



To add, I found the ivfolders.rb script and ran it from the Terminal against a folder containing 7 test images.



Creating six folders based on image creation date.




The new script works for me as well. Thank you very much for looking into this and sharing your time and knowledge, much appreciated:-)

You are welcome.