Convert from ASCII to Unicode

Hello all,

I am trying to create a folder action script that converts a file from plain ASCII 1256 text and save it as Unicode in the save it in the same place with the same name.
I found a script in the forum that converts UTF - 16 to UTF 8 i tried to modify it but couldn’t fine the right command for ASCII.
Here’s the code

set theFile to alias "path:to:file"
set fref to (open for access theFile with write permission)
set oldContents to (read fref as "i dont know how to set it as ascii" )
set eof of fref to 0
write oldContents to fref as Unicode text
close access fref

This is an urgent matter and any help will be greatly appreciated.
Regards,
Psycho-ed

Hi,

the read/write commands of AppleScript can only convert MacRoman (Macintosh ASCII), UTF-8 and UTF-16 formats.
To convert other formats use textutil

try this


do shell script "/usr/bin/textutil -convert txt -encoding UTF-16 -inputencoding windows-1256 " & quoted form of POSIX path of (choose file)

Thanks StefanK. It was exactly what i wanted.

Psycho-ed

I needed this too, I have a large folder of PHP-files that are Windows (Latin 1), and this seems to be a good start :slight_smile:

BUT … can I get the output-files to be put in another directory with file-ending = filename.php?

AND can I keep my Danish ÆØÅ æøå chars - this script does “something” to them, and I need them untouched.

Newbie Scritper here btw, so any help is greatly appreciated :slight_smile:

Thank you in advance,
Cheers Thomas