How to automate this repetitive task

automatorfinder

Automator would seem to the appropriative tool, but ehmac.ca is stumped and so has this board been so far — my "Automator Newbie" question asked yesterday (my first ever on this site). Two sticking points — changing the .tiff extension to .tif, and losing the Alpha option.

The problem to be solved is prepping a large collection of edited scanned text files in tif format and getting them ready for processing by the OCR app TesseractGUI 0.3. This OCR app balks at TIF files with an extension of .tiff, also balks at Alpha within the file format.

Here's the manual routine I've been using.

  1. Open the file in Preview.
  2. From the File menu choose the Export command.
  3. Click in the file name field and delete the second "F".
  4. Uncheck the Alpha option.
  5. Click the Save button.
  6. In the next dialogue choose the "Replace" option.
  7. Close the window.
  8. Rinse and repeat with the next file in the list.
  9. Exit when all files have been prepped.

Appreciated.

Best Answer

This works in my tests and should give you a starting point.

I use two actions to get the folder and its contents.

  • Get Selected Finder Items
  • Get Folder Contents

Then using a 'Rename finder items' Action. I change the extension with it's settings set to:

Replace Text

Find: tiff in extension only - ignore case Yes

Replace: tif


Then a 'Run Shell Scrip' Action using the unix command sips I change the format of the files to jpeg and then back to tiff. This removes the alpha channel.

It's settings are :

  • Shell: /bin/bash
  • Pass input: as Argument

With the code:

for f in "$@"
do

 /usr/bin/sips -s format jpeg  "$f"; /usr/bin/sips -s format tiff  "$f"

done

enter image description here

To use I select the folder with the Images and run the workflow on it. It will also work on a single or multiple images if that is what is selected instead of a folder


Update. User @chananelb pointed out that the is an Automator Action that can change the file type. But since they did not put any instructions in how this could be done. I will add it here as an alternative option.

The input of the service stays the same. And the first action as discussed in the comments should be Get Folder Contents.

All other actions can be removed and two actions of Change image type should be added.

The first Change image type is set to jpeg.

The second is set to tiff.

Thats it simple.

enter image description here Open bigger image