I didn’t use applescript since I use Tiger.
I am trying to break a filemaker 8 exported text file into several different files all with the same “.tab” extensions.
This script worked well with Panther and Filemaker tabs but now Apple script editor crashes every time I call the script
In The FileMaker file I have tabs delimiting each field(with or without any text in them) none of the eported fields has any line feeds or carriage returns. Each record ends with a carriage return.
What am’I doing wrong?
Thanks
on run
open {choose file with prompt "Locate the source file"}
end run
on open the_file
try
set the_file to item 1 of the_file as alias
set target_folder to (choose folder with prompt "Where should I save the files") as string
set the_paragraphs to paragraphs of (read the_file)
set old_atid to AppleScript's text item delimiters
repeat with i from 1 to count of the_paragraphs
set this_paragraph to (item i of the_paragraphs)
set AppleScript's text item delimiters to {return}
set the_base_name to text item 1 of this_paragraph
set AppleScript's text item delimiters to {""}
set the_dupe to 0
set new_name to (target_folder & the_base_name & ".tab")
repeat
try
get new_name as alias
set the_dupe to the_dupe + 1
set new_name to (target_folder & the_base_name & "_" & (the_dupe as string) & ".tab")
on error
exit repeat
end try
end repeat
my write_to_file(new_name, this_paragraph, false)
end repeat
set AppleScript's text item delimiters to old_atid
beep
display dialog ((i as string) & " files were saved. (" & ((current date) as string) & ")") buttons {"OK"} default button 1 with icon 1 giving up after 30
on error the_error
beep
try
my write_to_file((target_folder & the_base_name & "_Error" & "." & the_extension), the_error, false)
end try
display dialog the_error buttons {"OK"} default button 1 with icon 0 giving up after 30
return
end try
end open
on write_to_file(the_file, the_string, appending)
set the_file to the_file as string
try
set write_file to open for access file the_file with write permission
if appending = false then set eof of write_file to 0
write the_string to write_file starting at eof
close access write_file
on error
try
close access write_file
end try
end try
end write_to_file
Model: PowerBook PPC
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)