I want to pass the contents of a document through a Unix script and use the 
result in an AppleScript, and I'm running into a line-endings problem. For 
example, let's say my AppleScript is

tell application "BBEdit"
    set myText to contents of front document
    set lineCount to do shell script "echo " & quoted form of myText & " | 
wc -l | sed 's/ //g'"
    -- go on and do something with lineCount
end tell

This script returns values like "2" or "3" no matter how many lines the 
front document has (I always use Unix line endings and UTF-8).

I assumed the problem has something to do with line endings. To test this, 
I ran this AppleScript

tell application "BBEdit"
    set myText to contents of front document
    set tPath to path to desktop from user domain as text
    set tPath to tPath & "test.txt"
    set fileID to open for access tPath with write permission
    set eof fileID to 0
    write myText to fileID as class «utf8»
    close access fileID
end tell

and looked at the "test.txt" file in a hex editor. As I suspected, the line 
endings are OD (CR) instead of 0A (LF). Why is this, and what can I do to 
get "contents of front document" to return LFs instead of CRs?

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to