applescript no longer working since upgrade to monterey

The following applescript is no longer working since I upgraded to Monterey. Can someone please take a look and let me know how to fix this? I would SO appreciate it.

tell application "Finder"

set the_folder to choose folder
set the_folder_name to name of the_folder
set the_subfolders to every folder in the_folder
repeat with I from 1 to count of the_subfolders
	set file_name to name of every file of item I of the_subfolders
	set name of every file of item I of the_subfolders to the_folder_name & "-" & name of item I of the_subfolders & "-" & file_name
	move every file of item I of the_subfolders to the_folder
end repeat
--
-- optionally delete the subfolders
-- delete every folder in the_folder -- put two dashes in front of this line to comment it out

end tell

when I changed name to {name}, it still doesn't work (lol), but now the error is more explanatory. it says number -10003. Access not allowed. I did also try nesting two repeat loops, but that didn't help.

the two repeat loops attempt, still doesn't work, lol:

tell application "Finder"

set the_folder to choose folder
set the_folder_name to name of the_folder
set the_subfolders to every folder in the_folder as list
repeat with index from 1 to count of the_subfolders
	set actor to item index of the_subfolders
	set actor_name to name of item index of the_subfolders
	repeat with I from 1 to count of actor
		set {file_name, file_ext} to {name, name extension} of item I of actor
		set {name, name extension} of item I of actor to {the_folder_name & "-" & actor_name & "-" & file_name, file_ext}
	end repeat
	move every file of item index of the_subfolders to the_folder
end repeat
--
-- optionally delete the subfolders
-- delete every folder in the_folder -- put two dashes in front of this line to comment it out

end tell

It looks like you have a bigger problem, and I'll respond over on the separate thread you created for that.

so now the script runs, yay! Thanks for the help on the other thread. but now, for example let's say I have 10 files in one of the_subfolders. it will correctly rename and move 4, sometimes is correctly moving but renaming 1 file with 4 prefixes and 1 file with 2 prefixes, and then will move but not rename 4 files. so sometimes the second repeat loop isn't correctly working? I tried to do it with just one repeat loop, as above, but got an error message (1410), operation can't be completed. please note that the vast majority are moving correctly, it's like 6 files out of 33 in one test and none in the other, smaller test.

tell application "Finder"

choose folder
set the_folder to result
set the_folder_name to name of the_folder
set the_subfolders to every folder in the_folder as list
repeat with index from 1 to count of the_subfolders
	set actor to item index of the_subfolders
	set actor_name to name of item index of the_subfolders
	repeat with I from 1 to count of actor
		set file_name to name of item I of actor
		set name of item I of actor to the_folder_name & "-" & actor_name & "-" & file_name
	end repeat
	move every file of item index of the_subfolders to the_folder
end repeat
--
-- optionally delete the subfolders
-- delete every folder in the_folder -- put two dashes in front of this line to comment it out

end tell

It’s hard to offer advice here without having the info need to run your script. It seems like the script you posted is complete, so the only remaining detail is the file system hierarchy you’re working with. Please post a summary of what that looks like to start with and what you’re expecting it to look like when the script is done.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

applescript no longer working since upgrade to monterey
 
 
Q