How to create a UTF-8 encoded text file using do shell script? As I understand it, the command should start with do shell script. And what to write next?
These might come in handy:
-- fetch a file's utf8 content
on FetchFileData(filepath)
set {isopen, filedata} to {false, ""}
try
set fileID to (open for access (filepath as alias) without write permission)
set isopen to true
set filedata to read fileID from 0 to ((get eof fileID) - 1) as «class utf8»
close access fileID
set isopen to false
on error message number code
display dialog "error (" & code & ") reading file: " & message
if isopen then close access fileID
error message number code
end try
filedata
end FetchFileData
-- save a string as utf8 text
on StoreFileData(filepath, filedata)
set isopen to false
try
set fileID to (open for access file filepath with write permission)
set isopen to true
write filedata to fileID as «class utf8»
close access fileID
set isopen to false
on error message number code
display dialog "error (" & code & ") saving file: " & message
if isopen then close access fileID
error message number code
end try
end StoreFileData
-- note the « and » characters are produced by typing option-\ and option-shift-\ respectively.