Renaming script changes certain characters — Unicode problem?

Thanks to Member “peavine” I got an almost instant solution to the first problem I posted here (renaming a folder of files from a .csv list): https://macscripter.net/viewtopic.php?pid=209447#p209447

There’s a lingering problem: certain characters (from the text file) change into others (in the new file names): specifically, each “m-dash” (—) turns into

‚Äî‚

Is this a Unicode problem? Here’s the script (written by “peavine” as I mentioned):


set sourceFolder to (choose folder) as text
set fileRenamingData to (choose file) as text
set fileRenamingData to paragraphs of (read file fileRenamingData)

set ATID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}

tell application "Finder"
	repeat with i from 1 to (count fileRenamingData)
		set theData to item i of fileRenamingData
		if theData > "" then
			set sourceFile to sourceFolder & text item 1 of theData
			if (exists file sourceFile) then
				try
					set name of file sourceFile to text item 2 of theData
				on error
					display alert "A file with the name " & quote & (text item 2 of theData) & quote & " already exists and will be skipped"
				end try
			end if
		end if
	end repeat
end tell

set AppleScript's text item delimiters to ATID

Thanks in advance for any advice or assistance!
Jordan

Model: MacBook Pro 14" M1 Max
AppleScript: 2.8
Browser: Firefox 96.0
Operating System: macOS 12

Jordan. Changing the third line of my script as shown below fixed this issue in my testing.

set fileRenamingData to paragraphs of (read file fileRenamingData as «class utf8»)

According to Nigel, the reason this issue arises is:

https://macscripter.net/viewtopic.php?id=48020

Worked like a charm! Thanks again.

Jordan

Model: MacBook Pro 14" M1 Max
AppleScript: 2.8
Browser: Firefox 96.0
Operating System: macOS 12