rename files by modification date

I would like to change filenames of some unknown number and title in a folder. I would like to name them with a name (constant) and number (changes by number in list) in order of their modification date.
so far this is what I have come up with but i’m stuck
count1 is from the last command in my longer script

tell application "Finder"
	set count1 to 2
	repeat with i from 1 to count1
		try
			set myFolder to (path to music folder as Unicode text) & "Audio Hijack:paparimage:pageimages"
			set myfile to first item of ((sort files of folder myFolder by modification date) as list)
			set name of myfile to "ttbookpic" & i & ".gif"
		on error
			-- no files in the folder
		end try
	end repeat
	
end tell

Something like this:


set myFolder to (choose folder) -- or whatever
tell application "Finder" -- sort is a Finder function
	set Sorted to sort (files of entire contents of myFolder) by modification date -- returns a list, don't need as list
	set C to count Sorted
	repeat with k from 1 to C
		set name of item k of Sorted to "File # " & k & ".gif"
	end repeat
end tell

I tried the script below but got this error message.

have I specified the folder correctly?

set myFolder to (path to music folder as Unicode text) & "Audio Hijack:paparimage:pageimages:"
tell application "Finder" -- sort is a Finder function
	set Sorted to sort (files of entire contents of myFolder) by modification date -- returns a list, don't need as list
	set C to count Sorted
	repeat with k from 1 to C
		set name of item k of Sorted to "ttbookpic" & k & ".gif"
	end repeat
end tell

no you need to specify the variable is an alias buy puting this on the end of the first line , as alias

set myFolder to (path to music folder as Unicode text) & "Audio Hijack:paparimage:pageimages:" as alias

Thanks, I missed that. It works great now.