Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macmesser

macrumors 6502a
Original poster
Aug 13, 2012
921
198
Long Island, NY USA
I'm using Applescript to generate CSV files in Text Wrangler. What character do I need to append to my lines in Applescript for Text Wrangler to see it as a line break? "¬" is not working. Perhaps an ASCI code? Help greatly appreciated.
 
For Windows its two ASCII characters: CR (13th character) and LF (10th character). Everyone else uses LF. As long as you don't need Windows you can just use LF.

You should be fine with adding:
Code:
\n
whenever you need it. Note the non-standard slash. It allows you to type a character that normally is impossible.
 
  • Like
Reactions: macmesser
Could you not just use the word "return" in your AppleScript? Here's a snippet to show what I mean:

Code:
set theList to {"apple", "orange", "banana"}

set AppleScript's text item delimiters to return
set theTextList to theList as text --change the list to text using 'return' to separate items
set AppleScript's text item delimiters to ""

do shell script "echo " & quoted form of theTextList & " > ~/Desktop/output.csv"
 
  • Like
Reactions: macmesser
For Windows its two ASCII characters: CR (13th character) and LF (10th character). Everyone else uses LF. As long as you don't need Windows you can just use LF.

You should be fine with adding:
Code:
\n
whenever u need it. Note the non-standard slash. It allows you to type a character that normally is impossible.

Thanks for reply. My Applescript is rusty. Wili text Wrangler (or other text editor) recognize LF as a new line? Will look as maybe it's a preference. When "show invisibles" is chosen under text display menu choice a ¬ is shown at the end of every line, which is what I was using in my Applescript as
Code:
to end lines. An unquoted ¬ allows line continuation in Applescript editor. I will try the escaped n.
[doublepost=1456920205][/doublepost]
Could you not just use the word "return" in your AppleScript? Here's a snippet to show what I mean:

Code:
set theList to {"apple", "orange", "banana"}

set AppleScript's text item delimiters to return
set theTextList to theList as text --change the list to text using 'return' to separate items
set AppleScript's text item delimiters to ""

do shell script "echo " & quoted form of theTextList & " > ~/Desktop/output.csv"

Thanks for response. I remember "return" now. The Applescript part of your code, up to the last line will certainly work exactly as shown in my script. Not knowing Unix commands : ( , I don't fully understand the last line. I should start to learn Unix (and brush up on Applescript).

Thanks to both of you I have two Applescript line breaks to try when passing text to Text Wrangler. Started the morning off right as I was just about to resume work on my script and somewhat dreading it. : )
 
Last edited:
Thanks for response. I remember "return" now. The Applescript part of your code, up to the last line will certainly work exactly as shown in my script. Not knowing Unix commands : ( , I don't fully understand the last line. I should start to learn Unix (and brush up on Applescript)

Don't worry about the Unixy bit, that's just me writing the CSV text to file. You could do it using AppleScript's native "write file" but personally I find it fiddly and prefer to use a little 'do shell script'. If you want to do it natively using AppleScript then you can find more info here.

http://www.macosxautomation.com/applescript/sbrt/sbrt-09.html

Good luck!
 
  • Like
Reactions: macmesser
Wili text Wrangler (or other text editor) recognize LF as a new line?
textwrangler.png

In the TextWrangler preferences you can set the type of newline character you want to use. Modern Mac uses the Unix standard since day one of OSX, I believe.

Most text editors hide the newline character, but all will understand the specific character it expects. So if you open a Mac formatted document in Windows, it will be all on one line. If you open a Windows formatted document in OSX, you will have a strange character at the end of every line.

I have always used \n, because the code is translated to the correct character. I doubt that ¬ is correct, unless it is specific to an interpreter. The newline character is part of the whitespace character set like space and tab, so they do not have an official symbol.
 
  • Like
Reactions: macmesser
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.