Photos - Raw & Jpg Files

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

Moderator: Mr_Noodle

Photos - Raw & Jpg Files Fri Mar 15, 2013 12:04 am • by laurie_lewis
Hi,

I am trying to come up with a workflow to automatically delete files that have the same file name but different extensions. At times I take photos as both Raw and Jpg. This creates two files with the same unique name but different extensions:

IMG_00123.CR2
IMG_00123.JPG

They are both in the same directory and at this time I know they are identical so it is the best time to cull the JPG. What I would like to do with Hazel is as soon as I put the SD card into my machine have it scan the directory and if it finds two files with the same file name to delete the one with the JPG extension. Then I can do the rest of my workflow as normal.

I have found some applescripts that will do it within iPhoto but nothing for Hazel.

Thanks

Laurie
laurie_lewis
 
Posts: 23
Joined: Thu Mar 14, 2013 11:53 pm

Re: Photos - Raw & Jpg Files Fri Mar 15, 2013 12:09 am • by laurie_lewis
I did find the following but it is a command line solution. Not sure if it can be incorporated into Hazel

In your command prompt, go to the folder and run this:

for /f "delims==" %r in ('dir /b *.nef') do del "%~dpr%~nr.jpg" 2> nul

Basically, it goes through the current folder, runs through the .NEF files, and deletes the JPG if present. It ignores any errors if the JPG is not there.

If you want subfolders, include "/s" (without quotes) in the dir command.


Laurie
laurie_lewis
 
Posts: 23
Joined: Thu Mar 14, 2013 11:53 pm

Re: Photos - Raw & Jpg Files Fri Mar 15, 2013 6:16 am • by laurie_lewis
I run the line in Terminal (OSX) and I get the following:

Laurences-iMac:100CANON Laurie$ for /f "delims==" %r in ('dir /b *.CR2') do del "%~dpr%~nr.jpg" 2> nul
-bash: syntax error near unexpected token `"delims=="'
Laurences-iMac:100CANON Laurie$


Any ideas on what I need to do?

Laurie
laurie_lewis
 
Posts: 23
Joined: Thu Mar 14, 2013 11:53 pm

Re: Photos - Raw & Jpg Files Fri Mar 15, 2013 12:11 pm • by a_freyer
Passes shell script:

Code: Select all

filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"

if [ -a "$filename.CR2" ]; then
     exit 0;
fi

exit 1;


Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     kind is jpg
     passes shell script

Do the following to the matched file or folder:
     move file to trash



This will only match JPGs that also have a CR2 file with the same name the same directory.

Note: I did not test, as I am not on my mac right now
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Photos - Raw & Jpg Files Fri Mar 15, 2013 12:57 pm • by Mr_Noodle
Unfortunately, right now match tokens from previous conditions don't appear in later conditions (only in the actions). I think I have it in the feature list and if/when I implement it, you should be able to do something like this:
Code: Select all
If (all) match for the (file being matched)
    Name matches (•name)
    If (all) match for the (enclosing folder)
        If (all) match for (any sub-file)
            Name matches (•name)
            Extension is cr2

In this hypothetical situation, the first •name (which is set to be "anything") would match the name of the jpeg file and store it. The other conditions match if the folder containing this file also contains a file matching that same name (by referencing the previously stored name) but with a cr2 extension.

So, you'll have to use a script for now but hopefully this will be doable (albeit in a meandering way) in the future using the built-in conditions.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Photos - Raw & Jpg Files Fri Mar 15, 2013 4:21 pm • by a_freyer
Mr_Noodle - that would be a GREAT feature. very handy.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Photos - Raw & Jpg Files Fri Mar 15, 2013 10:00 pm • by laurie_lewis
Thank you a_freyer that works just perfectly. The missing piece for my photo workflow.

Mr Noodle, thank you for a great bit of software. I have not idea how to push it to the edge but it is a must have in my opinion.

Laurie
laurie_lewis
 
Posts: 23
Joined: Thu Mar 14, 2013 11:53 pm

Re: Photos - Raw & Jpg Files Sat Mar 16, 2013 12:38 am • by laurie_lewis
Ok I am still having a few issues so some other questions if I can

Step 1:- Move Files From SD Card to Local Hard Drive Directory upon insertion of SD Card

Code: Select all
if all  conditions met for the file/folder bing matched
   kind is folder
Run rules on folder contents

if any of the following are met for the file or folder being matched
   kind is image
   kind is movie
move to folder Imported Photos


This leaves me with a clean SD card to put back in Camera or bag

Step 2:- Monitor Folder for import and move jpg duplicates of CR2 files to directory for manual deletion or whatever. Copy remaining files (No duplicate JPG Files) to drive on NAS (also monitored for renaming and sorting) for backup. Finally import files into Aperture and delete imported (Still working on this Aperture part)

Code: Select all
RULE 1

if all the following conditions are met for file or folder
    kind is JPEG image
    Passess shell script embedded script
move to folder for duplicates

{Embedded Script}
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"

if [ -a "$filename.CR2" ]; then
     exit 0;
fi

exit 1;

RULE 2

if all the following condtions are met for the file or folder being matched
    extension is CTG
Move to Trash

RULE 3

if all the following conditions are met for the file or folder being matched
    kind is image
copy to NAS directory
Run AppleScript embedded Script

{Embedded Script}
tell application "Finder"
   delay 5
end tell


RULE 4

Aperture Stuff


The problem I am having is that files are being copied to the NAS (Rule 3) before ALL the duplicate JPG files are moved out of the directory as being done in Rule 1. It also appears to be having problems in that it is now not picking up all the duplicates.

I am just testing this one part at a time before moving to the next one. Had it planned out in advance They key part being getting rid of those CR2/JPG duplicates.
laurie_lewis
 
Posts: 23
Joined: Thu Mar 14, 2013 11:53 pm

Re: Photos - Raw & Jpg Files Mon Mar 18, 2013 2:14 pm • by Mr_Noodle
Is it possible that the CR2 hits the folder first, Hazel sees a solitary CR2 without the jpg and treats it as such before the accompanying jpg gets moved over?
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

laurie_lewis Tue Mar 19, 2013 5:17 am • by laurie_lewis
You are 100% correct Mr Noodle. Based on that I decided to run I tried to run it directly from the SD card when it was inserted. I still get the same problem.

What I need to happen is for the first rule to be completed on all the files prior to the second, third, etc rules being started. I put a wait command into the second rule but depending upon the number files in the directory you can get problems towards the end or it takes too long.

Any ideas?

Thanks

Laurie
laurie_lewis
 
Posts: 23
Joined: Thu Mar 14, 2013 11:53 pm

Re: Photos - Raw & Jpg Files Tue Mar 19, 2013 8:00 am • by laurie_lewis
Over thinking it.

Rule 1: move extension cr2
Rule 2: move kind jpeg image

Now all cr2 files there to check the jpg against in target directory.

I can then use colours to track whether additional steps are done for my backups etc.

I am thinking this will always work as rule 1 is applied to all file names in directory before rule 2 is applied to remaining files. Is that correct?

Laurie
laurie_lewis
 
Posts: 23
Joined: Thu Mar 14, 2013 11:53 pm

Re: Photos - Raw & Jpg Files Tue Mar 19, 2013 1:09 pm • by Mr_Noodle
The rules are matched in order and only the first one to match will be executed, if that's what you are getting at.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Photos - Raw & Jpg Files Sun Sep 10, 2017 5:06 pm • by YannB
I'm trying to do the exact same thing, but it's 2016 now… What's the recommended way to achieve this result now?

I have a bunch of folders of old pictures I'm trying to cleanup… Some files have up to 5 file types with different extensions but same file name:

DSC_0153.JPG
DSC_0153.NEF
DSC_0153.NEF.plist
DSC_0153.NEF.preview
DSC_0153.NEF.thumbnail

But some of the images only have a JPG version, so it's not as easy as trashing all non-NEF formats…

I basically need to trash anything that's not a NEF, IF there's a NEF file with the same name… Do I need to use a shell script for that? If so, any tip on what the script would look like would be much appreciated :P

Thanks!
YannB
 
Posts: 6
Joined: Fri Jun 07, 2013 11:21 pm

Re: Photos - Raw & Jpg Files Mon Sep 11, 2017 11:08 am • by Mr_Noodle
If you look earlier in this thread, there's an example there. The feature I alluded to not being implemented yet has now been implemented so the example should work with some tweaking.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Photos - Raw & Jpg Files Tue Sep 19, 2017 4:24 am • by Dave61
I assume that only some of the .jpg files are duplicates of a .raw file (otherwise, you would just delete them). So, completely different approach without scripts:

1) copy all files from SD card into folder A
2) move all with extension .jpg to folder B
3) label all .raw files as "Red"
4) rename all .raw files with extension .jpg (bear with me)
5) move all ".jpg" files to folder B, overwriting existing files
6) rename all "red" files with extension .raw
7) remove "red" label
Dave61
 
Posts: 114
Joined: Tue Jul 10, 2012 4:56 pm


Return to Support