script to label "dupes"

I have an old script that won’t run now due to the ‘move’ bug in apple events. Can someone help with a fix? I’m only good enough at applescript to be dangerous to myself.

somehow i ended up with a large amount of ‘dupe’ files in a folder. they’re not really dupes-they’ve been renamed like file.jpg, file 1.jpg

So, I’ve written a script to identify and create an array of the filenames with a space in the name. Then, when the apple events ‘move’ command still worked, it was trivial to move them to another folder.

But, now I’m stuck. I can’t easily move them in the finder due to the way I’ve collected the file names. Is there another way to easily group these files? I thought maybe labeling them and then sorting in the finder by label?

Here’s the script so far. Any ideas would be welcome. thanks.

set sourceFolder to POSIX path of (choose folder with prompt "Select folder with all files to parse.")
set targetFolder to (choose folder with prompt "Select the destination folder for the dupes?")
set searchString to text returned of (display dialog ¬
	"Select a string to search" default answer " 1.jpg")
do shell script "find " & quoted form of sourceFolder & " -iname *" & quoted form of searchString & " ; true"
set theFiles to paragraphs of result

display dialog "Move " & (count theFiles) & " files." default button "Cancel"

-- 7/4/2022 System Events move command is broken as of 10.9
tell application "System Events"
	move theFiles to targetFolder
end tell

cudaboy_71. The issue with System Events is that it doesn’t work with system aliases. So, if you want to stick with your existing script, the following works on Monterey. I don’t quite understand your idea of labeling the duplicate files in Finder and can’t offer any advice on that.

set sourceFolder to POSIX path of (choose folder with prompt "Select folder with all files to parse.")
set targetFolder to (choose folder with prompt "Select the destination folder for the dupes?")
set targetFolder to targetFolder as «class furl»
set searchString to text returned of (display dialog ¬
	"Select a string to search" default answer " 1.jpg")
do shell script "find " & quoted form of sourceFolder & " -iname *" & quoted form of searchString & " ; true"
set theFiles to paragraphs of result

display dialog "Move " & (count theFiles) & " files." default button "Cancel"

tell application "System Events"
	move theFiles to targetFolder
end tell

Hi. Assuming there are no other files with spaces in the name that you don’t want to relocate, here is a shell approach using mv (i.e. ‘move’).


do shell script "find " & my (choose folder)'s POSIX path's quoted form & " -name '* *.*' -print0 | xargs -0J % mv % " & my (choose folder)'s POSIX path's quoted form

–edited to simplify

Thanks Peavine & Mark Anthony!

Peavine, yours worked great.

I’m going to try to get Mark Anthony’s to work now, as well. Cheers!