Duplicate File selection in Finder

This is probably more of a Mac Finder question, but is there a way to select all files that are the original of a duplicate?

Explanation: we shoot images with CaptureOne. Sometimes the user realizes an adjustment is needed on an already processed image, and after making the adjustment, the image gets reprocessed. When the image is reprocessed, it will be the same file name with a “[space]1” after. At the end of the shoot, you have to clean up the Finder folder by deleting the original files, then renaming to remove the " 1".

Renaming is easy enough, but is there a way to select the all the images without the " 1" in order to delete them first? Select all cannot work because I only want to select the images that have been reprocessed.

When you could do is something like this:

Select all the files in the folder, then:

  • For Each Path in Finder Selection
    • Set variable New Path to %Variable%Path%
    • Search & Replace Variable New Path for " 1." with “.”
    • If text %Variable%Path% is not %Variable%New Path%
      • Trash File %Variable%New Path%
      • Move File %Variable%Path% to %Variable%New Path%

That will scan the folder looking for any files that have " 1." in the path anywhere, and if they do, it will rename the file to the path without the " 1", trashing any file that is in the way.

Now, if your folder name or path has " 1." or " 1." appears anywhere else in any file in your folder other than where you are expecting, then all bets are off and bad things will happen.

Hey Jimmy,

Please provide an exact sample of file names.

-Chris

Sure, filesnames would appear like this:

IMG_A.jpg
IMG_A 1.jpg
IMG_B.jpg
IMG_C.jpg
IMG_D.jpg
IMG_D 1.jpg

so in that case, we have to delete the IMG_A.jpg and then rename IMG_A
1.jpg as IMG_A.jpg. Same with D.

Hey Jimmy,

Thanks – that's crucial information.

Try out the appended AppleScript on a test folder, and make certain it works correctly.

NOTE: Currently the script operates on the front Finder window.

Found items are moved to the Trash, so recovery is possible if an error is made (and caught).

-Chris

--------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2016/06/08 23:01
# dMod: 2016/06/09 04:14
# Appl: ASObjC
# Task: Move files to Trash if they match a certain regular expression.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder
--------------------------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
--------------------------------------------------------------------------------

set regExPattern to "^.+(?<! 1)\\.(?i)[a-z]{3}$"
tell application "Finder" to set sourceFolder to insertion location as alias
set sourceFolder to POSIX path of sourceFolder
set fileList to its getFilePathsFromPath:sourceFolder usingRegex:regExPattern

if fileList ≠ {} then
   tell application "Finder" to delete fileList
else
   error "No files were found for deletion!"
end if

--------------------------------------------------------------------------------
--» HANDLERS
--------------------------------------------------------------------------------
on getFilePathsFromPath:sourceFolder usingRegex:regExPattern
   set fileManager to current application's NSFileManager's defaultManager()
   set theURL to current application's |NSURL|'s fileURLWithPath:sourceFolder
   set directoryContents to fileManager's contentsOfDirectoryAtURL:theURL includingPropertiesForKeys:{} ¬
      options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) ¬
      |error|:(missing value)
   set foundItemList to current application's NSPredicate's ¬
      predicateWithFormat:("lastPathComponent matches '" & regExPattern & "'")
   set foundItemList to directoryContents's filteredArrayUsingPredicate:foundItemList
   set foundItemList to foundItemList as list
   return foundItemList
end getFilePathsFromPath:usingRegex:

--------------------------------------------------------------------------------
1 Like

Wow, thanks for that applescript!

It’s giving me this error:

error “Finder got an error: Can’t get «class ocid» id «data optr00000000E0522A0000600000».” number -1728 from «class ocid» id «data optr00000000E0522A0000600000»

Yeah! This seems to be working. Will do more testing before fully implementing but I am much obliged!

Hey Jimmy,

What version of OSX are you using?

-Chris

We’re still running 10.10.5, haven’t upgraded yet.

Ah, that's the problem.

I'm not sure if I can work around it or not. I'll get back to you if I can.

-Chris

No worries if not, Peter’s Keyboard Maestro steps above worked. Thanks though!