• 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
Reading file containing UTF-8
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading file containing UTF-8


  • Subject: Reading file containing UTF-8
  • From: Tom Robinson <email@hidden>
  • Date: Wed, 05 Nov 2003 13:44:32 +1300

Hi folks,

Ibm reading a file which has been produced by the ls command. This file contains some UTF-8 sequences and Ibm having trouble getting them into AppleScript.

I think my two options are forcing the read command to produce a UTF-8 result, or some code to convert UTF-8 characters hidden in a string into Unicode text.

But Ibm fuzzy on the details and would appreciate a hand.

This is an extract from the code. Itbs using the find command to list details of all the files and folders in the Desktop (including sub-folders). It will fall over with an error 10 bNSCannotCreateScriptCommandErrorb when encountering a file with high ASCII characters (my test file uses an em-dash).


property linefeed : ASCII character 10 -- Unix

do shell script "find /Volumes/Valkyrie/Users/tom/Desktop -exec ls -ldp {} \\; > ~/Desktop/\"Temporary Find List6.txt\""
-- -l is long format, -d doesnbt descend in directories, -p prints a trailing slash for directories

set tempHandle to open for access file ("" & (path to desktop) & "Temporary Find List6.txt")
set tempEOF to 0

repeat until tempEOF = 1
try
set rawLine to read tempHandle until linefeed

set thisItem to text (offset of "/" in rawLine) through -2 of rawLine
log class of thisItem -- *** string, but can contain UTF-8 sequences inside it

log "Doing " & thisItem
set aThisItem to alias POSIX file thisItem

-- *** processing here

on error errText number errNum
if errNum b -39 then -- If not EOF
log "TError: Got " & errNum & ": " & errText
end if
set tempEOF to 1
end try
end repeat

close tempHandle


Background:

I originally wrote this using AppleScript to recurse into folders, but it was pretty slow (itbs going to be used over my whole disk).

Ibm no AppleScript expert, any off-subject suggestions about the code also appreciated.

Cheers
--
Women DO come with instructions. Just ask them!
_______________________________________________
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.

  • Prev by Date: Re: storing preferences
  • Next by Date: Re: Safari/Entourage question
  • Previous by thread: Re: Safari/Entourage question
  • Next by thread: Re: Reading file containing UTF-8
  • Index(es):
    • Date
    • Thread