Check Image has Correct Extension

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Check Image has Correct Extension 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
Paul1762
 
Posts: 49
Joined: Sat Nov 08, 2014 5:32 pm

Re: Check Image has Correct Extension 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.
Dave61
 
Posts: 113
Joined: Tue Jul 10, 2012 4:56 pm

Re: Check Image has Correct Extension 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
Paul1762
 
Posts: 49
Joined: Sat Nov 08, 2014 5:32 pm

Re: Check Image has Correct Extension 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
luomat
 
Posts: 78
Joined: Wed Mar 10, 2010 3:57 pm

Re: Check Image has Correct Extension 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
Paul1762
 
Posts: 49
Joined: Sat Nov 08, 2014 5:32 pm

Re: Check Image has Correct Extension 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.
luomat
 
Posts: 78
Joined: Wed Mar 10, 2010 3:57 pm


Return to Support

cron