|
 |
Quick Find |
 |
|
 |
Categories |
 |
|
 |
Information |
 |
|
|
|
| 
Text File Split with Applescript
Recently I was doing a project that required me to make over 2000 web pages. It was for a searchable database of images and the images needed to be embedded into a web page along with keywords and captions. I'm sure there's a perl script that could have built the pages on the fly, but making real pages works better for what we need.
I decided to use the keyword database we already had to make on huge text file with every line representing a different page that needed to be made. To simplify things I used Server Side Includes so I can change the layout of the resulting pages in a snap, but I still had the problem: how to get each line into a file with the correct name. For a previous project I used a DOS program that split a text file every X lines, but I still had to go through all 600 files and name them by hand. It took the better part of a day to do and was a real pain in the wrist. This time I wanted to do it all automatically.
On the Dos/Windows side I found plenty of utilities that could split text files, but none that would take the first "word" from that file and use it for the filename. I turned to Applescript and BBEdit (because "it doesn't suck" - that's really their motto!). I'm putting up this page so that hopefully someone else who needs to do this won't have to spend 2 hours figuring out how to do it.
Script Requirements:
BBedit (I used 6.5, but I bet you could get by with the "lite" freeware version on their site
Jon's Commands (freeware, it provides the conection with the clipboard)
Here's the Script:
repeat
tell application "BBEdit 6.5"
activate
select display_line 1 of text window 1
cut selection
make new text window
paste
select first word of text window 1
cut selection
set var1 to the clipboard
save text window 1 to file var1
close text window 1
end tell
end repeat
Enjoy!
Chris Bair
|