Carriage Return Woes

Hello,

I am trying to write an XML file to load into a program that runs on a windows machine. The problem I am having is that the Carriage returns are not being represented properly and the import is erring out. The following looks just fine when opened with text edit but when opened with “Notepad” the carriage returns are shown as little squares and all the text is on the same line. The text has to be formated as unicode text.

set theId to 1

set theFile to quoted form of POSIX path of ((path to desktop folder as string) & "XMltest.txt")


set eventSectionTag to ("<EVENT_SECTION>")
set eventTag to ("<EVENTID>" & theId & "</EVENTID>")
set eventSectionClosingTag to ("</EVENT_SECTION>")



set theEvent to quoted form of (eventSectionTag & return & eventTag & return & eventSectionclosingTag & return) as Unicode text
do shell script "echo " & theevent & ">" & theFile

return theEvent

Hi Dallas,

try LF (linefeed) or even CRLF

Hi Stefan, thanks for the reply. I can’t seem to get either of them to work. Once again proves the fact that I hate windows.

So do I :lol:

Upon further searching of why this is so I found a little tidbit apparently Notepad needs a carriage return and a line feed. So this seems to work. I don’t understand why it needs this but it seems to work.


set cr to ASCII character 13 -->You can probably use the Unicode Equivalent but I didn't know it and this worked right away.
set LF to ASCII character 10 --> Same as here
set carriage_return to (cr & LF as Unicode text)


set theId to 1

set theFile to quoted form of POSIX path of ((path to desktop folder as string) & "XMltest.txt")

set eventSectionTag to ("<EVENT_SECTION>") as Unicode text
set eventTag to ("<EVENTID>" & theId & "</EVENTID>") as Unicode text
set eventSectionclosingTag to ("</EVENT_SECTION>") as Unicode text


set theEvent to quoted form of (eventSectionTag & carriage_return & eventTag & carriage_return & eventSectionclosingTag & LF)
do shell script "echo " & theEvent & ">" & theFile

return theevent

Hey, I told you

I guess you did, I didn’t know what you were talking about. I am little slow on the pick up sometimes.
Thanks Stefan.

So is this code safe to use universally then? Could I set this as properties at the top of my scripts, and just always use the carriage_return variable instead of “return”, or are there cases where having the double linefeed will mess something up?

For which purpose?

the CRLF line delimiter is only needed, if your scripts create any text files for windows