PDA

View Full Version : adding carriage return in text output




sethdowd
Jun 30, 2011, 03:57 PM
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.

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



TEG
Jun 30, 2011, 04:09 PM
To create a new line, simply add \n to your string.

TEG

sethdowd
Jun 30, 2011, 04:35 PM
As in...?

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]

balamw
Jun 30, 2011, 07:59 PM
Just before the closing quotes.

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

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] \n" ...

You might be better off adding code after this line that just concatenates on a "\n" to the end of res.

B