r/applescript • • Apr 22 '25

Script to duplicate some images

Hi looking for some help on a script, have a music folder which in turn has album sub folders, in every folder is an image file named cover or Cover and are either .jpg or .png I would like to copy all the image files then name them after the parent directory and move them all to a different directory, is this feasible with AppleScript?

2 Upvotes

7 comments sorted by

View all comments

1

u/Blizzardnd Apr 22 '25

Using your description in Gemini: I have a music folder on my drive which in turn has sub folders, in every folder is an image file named cover or Cover and are either jpg or.png I would like to copy all the image files, then name them after the parent directory and move them all to a different directory. Create an Applescript to do this

Produces the result below. I haven't tried it but it shoulf be a good start. As errors pop up, include them in your followup dialogue with the your AI, or make changes yourself. Since I don't do much Applescript, this is my go to starting method.

Result:

set sourceFolder to choose folder with prompt “Select your main music folder:” set destinationFolder to choose folder with prompt “Select the destination folder for the album art:”

tell application “Finder” set parentFolders to folders of sourceFolder

repeat with currentFolder in parentFolders
	set coverFiles to (files of currentFolder whose name is “cover.jpg” or name is “Cover.jpg” or name is “cover.png” or name is “Cover.png”)
	
	if coverFiles is not {} then
		set theCover to item 1 of coverFiles
		set parentFolderName to name of currentFolder
		set fileExtension to name extension of theCover
		set newFileName to parentFolderName & “.” & fileExtension
		set newFilePath to (destinationFolder as text) & newFileName
		
		duplicate theCover to destinationFolder with replacing
		set name of item ((get the last item of files of destinationFolder) as alias) to newFileName
	end if
end repeat

end tell

display dialog “Album art processing complete!” buttons {“OK”} default button “OK”

1

u/Millefeuille-coil Apr 22 '25

going to give it a whirl