Creating subfolders and placing a file in each subfolder

I am having problems putting a file in each subfolders after creating the subfolders. Using automator to creating the subfolders and then using AppleScript to populate the subfolder with a file.

I select the folder in automator then pass this folder in a variable Myfolder over to AppleScript.

Here is the coded I have used below. Any help would be appreciated


on run {input, parameters}

set MyFolder to input as text #set MyFolder to path to current user folder
display dialog MyFolder

set MyFile to "Macintosh HD:Users:Razzle:Lightroom:Test:_Full Shoot:image.jpg"

display dialog MyFile

tell application "Finder"

	set SubFolders to every folder of entire contents of MyFolder
	repeat with aFolder in SubFolders
		display dialog aFolder as string
		duplicate MyFile to aFolder with replacing
	end repeat
end tell

end run

Hi.

Your script’s coercing the input list to text and then trying to get the ‘entire contents’ of that text. It also tries to duplicate the text to which you’ve set MyFile to each subfolder, but the Finder seems to understand what’s meant in that case. Still, it’s better to use a specifier there too.

on run {input, parameters}
	
	set myFolder to item 1 of input -- not 'input as text'.
	display dialog (myFolder as text)
	
	set MyFile to "Macintosh HD:Users:Razzle:Lightroom:Test:_Full Shoot:image.jpg"
	
	display dialog MyFile
	
	tell application "Finder"
		
		set SubFolders to every folder of entire contents of myFolder
		repeat with aFolder in SubFolders
			display dialog aFolder as string
			duplicate file MyFile to aFolder with replacing -- NB. 'file MyFile' to make a file specifier.
		end repeat
	end tell
	
	return input
end run