Re: Read a text file
Re: Read a text file
- Subject: Re: Read a text file
- From: Shane Stanley <email@hidden>
- Date: Fri, 01 Aug 2014 22:00:26 +1000
On 31 Jul 2014, at 5:05 am, Gil Dawson <email@hidden> wrote:
Where is TextWrangler getting this information?
From an extended attribute saved with the file, under the name com.apple.TextEncoding. This happens automatically with some Cocoa APIs -- for example:
use framework "Foundation" on writeString:aString toPath:posixPath set anNSString to current application's NSString's stringWithString:aString anNSString's writeToFile:posixPath atomically:true encoding:(current application's NSMacOSRomanStringEncoding) |error|:(missing value) end writeString:toPath:
Put that in an ASObjC-based library and run:
set thePath to POSIX path of ((path to desktop as text) & "Sample.txt") tell script "^" set theResult to its writeString:"Blah" toPath:thePath end tell
Change the encoding to NSUTF8StringEncoding and do it again, and you'll see that TextWrangler picks it up.
Where there are no extended attributes, it's a matter of trial and error, usually starting with UTF8, because it's much harder to misread destructively.
|
_______________________________________________
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