Re: Read a text file
Re: Read a text file
- Subject: Re: Read a text file
- From: Shane Stanley <email@hidden>
- Date: Thu, 07 Aug 2014 09:42:49 +1000
On 7 Aug 2014, at 1:12 am, Gil Dawson <email@hidden> wrote:
> So, when I used TextEdit to create those three ".txt" files, each with a different encoding in the "Save As..." dialog...
>
> One to UTF-8
> One to Western (MacOS Roman)
> One to Western (Windows Latin 1)
>
> ...the three files were not "plain text" files, but each must have had had an extended attribute saved with it (somewhere).
Technically they are still "plain text" files, if there is such a thing -- they are identical. Extended attributes are not actually saved within the file. That's why they aren't always available.
>
> I was wondering is there any way to pick up this extended attribute from within ASObj-C. Then I looked through the NSString class methods and I found:
> stringWithContentsOfFile:usedEncoding:error:
Just be aware that it's unreliable if the file in question does not have extended attributes. Again, trial-and-error is often safest. Start with UTF-8, because if a file is not UTF-8, and it uses more than ASCII characters, it is very, very unlikely to be able to read as UTF-8. So if UTF-8 fails, you can drop back to something else.
But there's no foolproof method.
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
_______________________________________________
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