Page 1 of 1

Check Image has Correct Extension

PostPosted: Wed Oct 02, 2019 4:48 pm
by Paul1762
I have a number of images that have an incorrect extension or a no extension.

is there a way that Hazel can rename an image to the correct extension by checking the image Exif?

if I use Terminal on my Mac

file -I filename

this shows some are incorrect.

Thanks Paul

Re: Check Image has Correct Extension

PostPosted: Thu Oct 03, 2019 6:13 am
by Dave61
The "Other" attribute gives you access to EXIF info (some/all?). There may be something in there that you can use.

Re: Check Image has Correct Extension

PostPosted: Thu Oct 03, 2019 1:44 pm
by Paul1762
Dave,
many thanks I will have a look at this and see if it will do what I want to achieve...

Paul

Re: Check Image has Correct Extension

PostPosted: Fri Oct 04, 2019 1:04 am
by luomat
This can be done fairly easily with a shell script.

The idea is straight-forward:

    1. Use `file -b` to see what 'type' a file is

    2. Assign an 'expected' file extension for each 'type' you want to look for

    3. Compare the 'actual' extension against the 'expected' extension.

    4. Rename if needed.

I made a zsh shell script which should work with Hazel to do just that. You can find it here:

https://gist.github.com/tjluoma/113ed4b45168a821d42ad7c372028737

Let me know if you have questions. (I'm following this thread, so I'll be notified of replies.)

ps - by default, the script only checks for PNG and JPEG/JPG but can be easily extended

Re: Check Image has Correct Extension

PostPosted: Fri Oct 04, 2019 3:55 pm
by Paul1762
thanks very much for this...

how do I use this in Hazel under the Run Shell Script?

do I place the code in a directory and then point the Shell: in the embedded script drop down to that directory?

Paul

Re: Check Image has Correct Extension

PostPosted: Sat Oct 05, 2019 10:45 am
by luomat
The easiest way to use it is to download it, open it in a text editor (BBEdit, Text Edit, etc) and copy everything to the clipboard.

Then open Hazel, add a “Run Shell Script” action, use “embedded script” and then click the ‘Edit Script’.

Paste the contents into the window that will appear.