adding carriage return in text output

Discussion in 'Mac Programming' started by sethdowd, Jun 30, 2011.

  1. sethdowd, Jun 30, 2011
    Last edited by a moderator: Jun 30, 2011

    macrumors newbie

    Joined:
    Jun 30, 2011
    #1
    I have a script that takes user input (date) then performs a query of the moneyworks.app then takes the resulting info and exports it to a .txt file. I am trying to insert linebreaks in between the data fields instead of tabs. Here is my script.
    Code:
    set dd to display dialog "Enter the date for the payments" default answer short date string of ((current date))
    set theDate to text returned of dd
    
    set dd1 to (date (theDate)) + 1 * days
    set dd2 to short date string of dd1
    tell application "MoneyWorks Gold.app" -- CheckDate  BankAcct  Check#  VendorNameCode  Invoice#  $AmountPaid
    	set res to «event BCIIEXPO» "payments#[lookup(cashtrans, `transaction.transdate`)]	[lookup(lookup(cashtrans, `transaction.contra`), `Account.bankAccountNumber`)]	[lookup(cashtrans, `transaction.ourref`)]	[lookup(invoiceid, `transaction.namecode`)]	[lookup(invoiceid, `transaction.theirref`)]  [amount]
    " given «class USRC»:"[transaction:type = `CPC` and timeposted >= '" & theDate & "' and timeposted < '" & dd2 & "'][payments.cashtrans]"
    end tell
    -- set the clipboard to res
    
    set filename to "MoneyWorks Export " & (word 1 of short date string of ((current date))) & "-" & (word 2 of short date string of ((current date))) & "-" & (word 3 of short date string of ((current date))) & ".txt"
    
    set theFilePath to (path to desktop as string) & filename
    set theFileReference to open for access theFilePath with write permission
    write res to theFileReference
    close access theFileReference
    
     
  2. TEG
    macrumors 604

    TEG

    Joined:
    Jan 21, 2002
    Location:
    Langley, Washington
    #2
    To create a new line, simply add \n to your string.

    TEG
     
  3. sethdowd, Jun 30, 2011
    Last edited by a moderator: Jun 30, 2011

    thread starter macrumors newbie

    Joined:
    Jun 30, 2011
    #3
    ok

    As in...?

    Code:
    	set res to «event BCIIEXPO» "payments#[lookup(cashtrans, `transaction.transdate`)]  \n
    	[lookup(lookup(cashtrans, `transaction.contra`), `Account.bankAccountNumber`)]	\n
     [lookup(cashtrans, `transaction.ourref`)] \n
    [lookup(invoiceid, `transaction.namecode`)] \n
     [lookup(invoiceid, `transaction.theirref`)]  [amount]
     
  4. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
    Just before the closing quotes.

    i.e. something like: (look for the red \n).

    Code:
    set res to «event BCIIEXPO» "payments#[lookup(cashtrans, `transaction.transdate`)]	[lookup(lookup(cashtrans, `transaction.contra`), `Account.bankAccountNumber`)]	[lookup(cashtrans, `transaction.ourref`)]	[lookup(invoiceid, `transaction.namecode`)]	[lookup(invoiceid, `transaction.theirref`)]  [amount] [B][COLOR="Red"]\n[/COLOR][/B]" ...
    You might be better off adding code after this line that just concatenates on a "\n" to the end of res.

    B
     

Share This Page