You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Finder script

I am working on a project where I capture thousands of images. I then need to put them in folders in finder by the batch name.


example:

76_3402-3411_001.JPG

76_3402-3411_002.JPG

76_3402-3411_003.JPG

76_3412-3432_001.JPG

76_3412-3432_002.JPG

76_3412-3432_003.JPG


They need to go into folders 76_3402-3411 and 76_3412-3432


Would love some help.

iMac 27″, macOS 11.2

Posted on Apr 12, 2021 7:39 AM

Reply

Similar questions

9 replies

Apr 12, 2021 8:24 AM in response to Scriptwriting

Try using:


tell application "Finder"

set the_folder to (choose folder)

repeat

set the_name to items 1 thru 12 of (get name of file 1 of the_folder) as string

if not (exists folder the_name of the_folder) then make new folder at the_folder with properties {name:the_name}

move file 1 of the_folder to folder the_name of the_folder

if (count (get files of the_folder)) is 0 then exit repeat

end repeat

end tell


(195929)

Apr 12, 2021 2:01 PM in response to Scriptwriting

From Dock : Launchpad : Other, open Script Editor. Copy/Paste Niel's script into the Script Editor, and click run.


It will open a folder chooser where you select the folder containing your image files. Once you select the starting folder it will set about creating the individual 12 character folders and moving the associated files into them. When the script finishes, you should see a bunch of new folders and no martian files that did not get placed in their respective namesake folder.

Apr 13, 2021 8:08 AM in response to Scriptwriting

Try using:


tell application "Finder"

set the_folder to (choose folder)

repeat (count (get files of the_folder)) times

set the_string to (get name of file 1 of the_folder)

set the_offset to offset of "_" in (items 4 thru -1 of the_string as string)

set the_name to items 1 thru (the_offset + 2) of the_string as string

if not (exists folder the_name of the_folder) then make new folder at the_folder with properties {name:the_name}

move file 1 of the_folder to folder the_name of the_folder

end repeat

end tell


(195983)

Finder script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.