• 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: Read a text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


-- 
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

  • Follow-Ups:
    • Re: Read a text file
      • From: Gil Dawson <email@hidden>
  • Next by Date: Re: Weird behavior of text in Pages
  • Next by thread: Re: Read a text file
  • Index(es):
    • Date
    • Thread