Struggling with text encodings

I am working with text files that I get from the Windows platform and which are encoded as “Western (Windows Latin 1)”. I am processing these files through an AppleScript and would like to save resulting text files as “Western (Mac OS Roman)” so that some other tool that I’m using interprets all characters correctly.

What I’m doing right now is that I’m opening the Windows text files manually in BBEdit (Open As: Western (Windows Latin 1)), save them as “Western (Mac OS Roman)”, and then run my AppleScript.

I may be able to script BBEdit to do this, but not all my users will have BBEdit, so I want to avoid using BBEdit.

So, my question is: how do I change a Windows Latin 1 encoded file to a Mac OS Roman encoded file? I’ve done some searching, but could not find the answer. Is there a command I can use?

Hi,

try this


on run
	set theFiles to choose file with prompt "Choose Windows Latin 1 files" with multiple selections allowed without invisibles
	open theFiles
end run

on open theseFiles
	repeat with oneFile in theseFiles
		do shell script "/usr/bin/textutil -convert txt -encoding macintosh -inputencoding ISO-8859-1 " & quoted form of POSIX path of oneFile
	end repeat
end open

Thx again for your help Stefan, I’ll give it a try!