• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Writeing text to file in UTF-16 little endian
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writeing text to file in UTF-16 little endian


  • Subject: Re: Writeing text to file in UTF-16 little endian
  • From: Takaaki Naganoya <email@hidden>
  • Date: Mon, 20 Apr 2009 19:58:49 +0900

Once write as UTF-16BE data and convert it to UTF-16LE by using iconv command.

<AppleScript>
--
set aDesktop to path to desktop
set aTDesktop to aDesktop as string
set aTDesktop to aTDesktop as Unicode text
set a to "TEST STRING" as Unicode text
set targetPath to aTDesktop & "outFile.txt"


saveInEncoding(a, targetPath, "UTF-16LE") of me --UFT-16LE --saveInEncoding(a, targetPath, "SHIFT_JISX0213") of me--Shift JIS --saveInEncoding(a, targetPath, "EUC-JISX0213") of me --EUC


on saveInEncoding(aText, aPath, aEncoding)

set a to aText as Unicode text

set aTmp to path to temporary items from user domain

set outFile to (aTmp as string) & "temporary_utf16be_text_fromAS.txt"
write_to_file(a, outFile, false) of me

do shell script "sync"

set outPPath to quoted form of POSIX path of (outFile as alias)
set cnvPPath to quoted form of POSIX path of aPath

try
do shell script "iconv -f UTF-16BE -t " & aEncoding & " " & outPPath & " > " & cnvPPath
end try

do shell script "sync"

try
do shell script "rm -f " & outPPath
end try

end saveInEncoding



on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error error_message
try
close access file target_file
end try
return error_message
end try
end write_to_file
</AppleScript>


On 2009/04/20, at 15:18, Sutapalli Satyanarayana wrote:

I wrote apple script that writes some text to a file in unicode format.
I know that by default it is in UTF-16 format. But how to confirm that I am writing in Little Endian only and how to check the output file whether it is in little endian or not.
My script is as following:


set the_file to (((path to desktop) as string) & "temp.txt") as file specification
open for access the_file with write permission --Open the file for writing and move to end of fle
set eof of the_file to 0
write ((ASCII character 254) & (ASCII character 255)) to the_file -- > not as Unicode text
.
.
.
.
--set writeRecord with some data
write writeRecord to the_file starting at eof as Unicode text
write ((ASCII character 13) & (ASCII character 10)) to the_file as Unicode text
close access the_file



By default "temp.txt" file will be in Big endian UTF-16 format. I want it to be in Little endian UTF-16 format.
How can I achieve this task with apple script


Thanks & Regards,
Satyam.


-- Takaaki Naganoya Piyomaru Software http://piyo.piyocast.com email@hidden

PiyoCast Web (Podcasting with Music!)
http://www.piyocast.com
Free AppleScript Library "AS Hole"
http://www.piyocast.com/as/



_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Re: Photomerge (From: Stan Cleveland <email@hidden>)
 >Simply deleting a fil (From: Satyam Satyanarayana <email@hidden>)
 >Re: Simply deleting a fil (From: Yvan KOENIG <email@hidden>)
 >Re: Simply deleting a fil (From: Tim Mansour <email@hidden>)
 >Writeing text to file in UTF-16 little endian (From: "Sutapalli Satyanarayana" <email@hidden>)

  • Prev by Date: Displaying Dialog on Remote Machine
  • Next by Date: Re: Photomerge
  • Previous by thread: Writeing text to file in UTF-16 little endian
  • Next by thread: Writeing text to file in UTF-16 little endian
  • Index(es):
    • Date
    • Thread