• 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: Can I recode strings in Applescript?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can I recode strings in Applescript?


  • Subject: Re: Can I recode strings in Applescript?
  • From: Bill <email@hidden>
  • Date: Sun, 29 Feb 2004 14:43:17 +0800

I just started toying around with AppleScript. I thought it would be fun
to try to syndicate my iTunes Recently Played list. But I'm having major
difficulty with the text encoding.

I've managed to get AppleScript to write an RSS file of the songs I've been
listening to. I can't get that file to validate, however, because I can
only encode the file in Mac OS Roman or full UTF 16.

If you are using write access, try class utf8. Below suggestion is modified from Apple's handler "Writing to File":

<http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.11.htm>


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 as B+class utf8B; to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file


Beware the mangled chevrons :)

The result file should be in UTF-8 encoding, that you don't need to convert the encoding.

Also, you may check the file with shell command 'file', e.g.:

-- in Terminal.app
$ file *.txt
Color of Law Investigations.txt: ASCII English text, with very long lines
Criminal confessions.txt: ASCII English text, with very long lines
Educating and Training the Future Police Officer .txt: UTF-8 Unicode English text, with very long lines
The vast majority of police officers.txt: ASCII English text, with very long lines
g62h7/f8e:.txt: UTF-8 Unicode text


Have fun ;)


bill
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Can I recode strings in Applescript?
      • From: Matthew Leingang <email@hidden>
  • Prev by Date: Re: How to make scripts reference multiple revs of an app
  • Next by Date: Re: How to make scripts reference multiple revs of an app
  • Previous by thread: Re: Can I recode strings in Applescript?
  • Next by thread: Re: Can I recode strings in Applescript?
  • Index(es):
    • Date
    • Thread