Applescript line break in Text Wrangler?

Discussion in 'Mac Programming' started by macmesser, Mar 1, 2016.

  1. macmesser macrumors 6502a

    Joined:
    Aug 13, 2012
    Location:
    Long Island, NY USA
    #1
    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.
     
  2. cruisin macrumors 6502a

    cruisin

    Joined:
    Apr 1, 2014
    Location:
    Canada
    #2
    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.
     
  3. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #3
    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"
    
     
  4. macmesser, Mar 2, 2016
    Last edited: Mar 2, 2016

    macmesser thread starter macrumors 6502a

    Joined:
    Aug 13, 2012
    Location:
    Long Island, NY USA
    #4
    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.
    --- Post Merged, Mar 2, 2016 ---
    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. : )
     
  5. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #5
    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!
     
  6. macmesser thread starter macrumors 6502a

    Joined:
    Aug 13, 2012
    Location:
    Long Island, NY USA
    #6
    Thanks again! Will check out the link.
     
  7. cruisin macrumors 6502a

    cruisin

    Joined:
    Apr 1, 2014
    Location:
    Canada
    #7
    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.
     
  8. macmesser thread starter macrumors 6502a

    Joined:
    Aug 13, 2012
    Location:
    Long Island, NY USA

Share This Page