I need to make a script which, when I drop a textfile on it,
removes a piece of text until the 5th semicolon (which is the delimiter in this text).
After that I have to replace the next semicolon by text1, the following semicolon by text2, and so on until I reach the end of the line.
The number of semicolons in each line is the same.
After that it should repeat the whole action.
Who can help?
Mac OS X Panther 10.3.3
It’s like a file exported from a spreadsheet program. A so called comma delimited file (CSV).
The program where it’s coming from is always exporting all the data, a to k.
I don’t need the first 5 cells, so I have to strip a to e and after that I want to fill in some text or returns in place of the ;
Here’s what I think might be close, although I’m not sure that I clearly understand the goal. Save this script as an application (it will become a droplet). To test the script, drop DUPLICATES of the actual files because it will modify the contents of the files. If it works then you can go from there and add error checking.
property replacements : {"1", "2", "3", "4", "5", "6"} -- the values which will replace the semi-colons.
on open files_
repeat with file_ in files_
set text_ to (read file_ using delimiter ";")
set temp1 to text 6 thru end of text_
set temp2 to ""
repeat with i from 1 to (count replacements)
set temp2 to temp2 & (item i of replacements & item i of temp1) as text
end repeat
try
set ref_ to open for access file_ with write permission
set eof of ref_ to 0
write temp2 to ref_
try
close access ref_
end try
on error
try
close access ref_
end try
end try
end repeat
end open
The goal of this script is to create a tagged text for indesign wich is containing al the layout commands.
I just can let it flow in a new document and the basic layout is ready.
Your piece is working great.
I changed the code to this:
This converts the text to tagged text for indesign.
When I import the text in indesign it’s completely formatted including paragraph styles.
Only 1 problem remaines.
When the sender is skipping one of the cells, so there is only a ; and no data in between, the replacement should also be skipped. Otherwise the script is producing unwanted data.
So I tried with an if-statement inside the second repeat (the bold faced text)