Applescript: filenames from folder to append to csv
For my bookkeeping I need to scan and store my receipts as a PDF file, but transfer some information (like amount and category) to an Numbers (Excel)-sheet as well. I'm using TextExpender to include al information needed for the Numberssheet inside the filename, which looks something like this:
UIT4,20130401,23,categoryA,.pdf
I want to transfer all the pdf-filenames in the folder to append to a csv file, so I get:
test.csv
UIT4,201304001,23,categoryA
UIT5,201305002,25,categoryB
UIT2,201306001,22,categoryA
etc.
I can import the csv in Numbers and all is well.
My question for you is how can I use applescript to get all the pdf-filenames in a folder to append to a csv-file?
I've tried this modified script by Pierre L, but I get a error regarding the ending of the file??
set theFolder to choose folder
set theTextFile to POSIX file "/Users/user_name/Desktop/test.csv" -- for example
set theText to readtheTextFile
tell application "Finder"
set theFileNames to name of files of theFolder whose name extension is "pdf"
repeat with thisName in theFileNames
try
set xx to (text 1 through 2 of thisName) as integer
set theNewFileName to paragraph (xx + 1) of theText
if character 3 of thisName is "-" then
set theNewFileName to theNewFileName & character 4 of thisName
end if
set name of filethisName of theFolder to theNewFileName & ".pdf"
end try
end repeat
end tell
If you'd like to help out, that would be great!
iMac, OS X Mavericks (10.9)