Split large CSV file into smaller files

Thanks so much for the update and the follow-up from both of you!

First off, let me say that I have figured out how to get smaller already-split-up files output from my source software, so I actually no longer really need the script.

That said, I really appreciate your work, and I know how unsatisfying it is to have code that just doesn’t work as you expect it to. So I did try your newest scripts and wanted to let you know the results anyway.

haolesurferdude: I ran your most recent script but took Yvan’s suggestion about the substitution. This time, when I ran it, it ran for about 6 minutes and made a “Levels.csv” and a “Targets.csv” then it threw an error:

error “Can’t get item 1 of {}.” number -1728 from item 1 of {}

Yvan Koenig: I ran your script and it has really got my MacBook Pro cooking with the fans running on high for the last 8 minutes. I have to step away from the computer now, but I’ll leave it running. So far no new files have been created.

If you guys want to test it yourself on the real file, I’ve uploaded a sample to here: https://dl.dropboxusercontent.com/u/1378250/main.csv

Like I said at the beginning, I am actually moving forward with a different solution, so I don’t need any follow-up on this, but if you want to get it solved for the future readers of this post, go for it!

I carefully asked you for the length of subfiles.
I carefully wrote that as you didn’t answer my question, I built the script assuming that the longer subfile was less than 10000 characters.

In the passed sample file, the first sublist descriptor is 3,251,721 bytes long.
It seems that you didn’t read my comments.

Edit the lines :

	# As is, assumes that the longer sublist descriptor is less than 10000 characters long
	set leTexte to read file theMainFile from beg for 10000

to

	# As is, assumes that the longer sublist descriptor is less than 4000000 characters long
	set leTexte to read file theMainFile from beg for 4000000

and the job will be done in a few seconds.

Your sublists are so long that one of them is breaking the row limit of Numbers.

Yvan KOENIG (VALLAURIS, France) mardi 16 décembre 2014 19:25:31

Thanks Yvan!!!

Merci beaucoup! (The best of what’s left of my French… My family moved from Bordeaux when I was seven.)

I always get great things from your wonderful work.

Sincerely,
:slight_smile:

Indeed! Thanks, Yvan. Sorry about not understanding and answering your questions about the length of the file.
Still, so glad to have found this forum. I’ll be sure to come back with any future AppleScript needs. :slight_smile:

Let’s keep it simple, assuming TARGETS comes after LEVELS:

set ti to current date

set f to "/Users/xpto/Desktop/main.text"
set fl to "/Users/xpto/Desktop/Levels.csv"
set ft to "/Users/xpto/Desktop/Targets.csv"


set f to open for access f
set t to read f
close access f


set fi to (offset of "Start_LEVELS\n" in t) + (count of "Start_LEVELS\n")
set fe to (offset of "END_LEVELS" in t) - 1

set fl to open for access fl with write permission
set eof fl to 0
write (text fi thru fe of t) to fl
close access fl
set t to text (fe + 1) thru -1 of t

set ft to open for access ft with write permission
set eof ft to 0
set fi to (offset of "START_TARGETS\n" in t) + (count of "START_TARGETS\n")

set fe to (offset of "END_TARGETS" in t) - 1
write (text fi thru fe of t) to ft
close access ft

log (current date) - ti

– started
(71)
– stopped

It still took a bit more than 1 minute. But hey, in an eMAc.

CAUTION, the sample main.csv file contain more than two lists bringing normally these files :

LEVELS.csv with 66528 lines
TARGETS.csv with 1044 lines
CHANNELS.csv with 199 lines
FIXTURES.csv with 60 lines
SHOWCONTROL.csv which is in fact just a line of titles

Yvan KOENIG (VALLAURIS, France) mercredi 17 décembre 2014 18:20:29

Hello folks! I’m back. This solution has been working well for me ever since you helped me arrive at it back in December 2014. But now, I’ve come across a new file that is giving the script problems.

To review, here is my current script:

# Define the path to the source CSV file
set theMainFile to (choose file with prompt "Select EOS CSV file..." of type {"csv"}) as text

tell application "System Events"
	set sourceLength to size of file theMainFile
end tell
# Define (and possibly create) the folder where new files will be stored
set p2f to "Mandela:Users:Jake:JDLD:01-Projects:UPH Local:04-HiLight:" as text
set storage to "Import"
set targetFolder to p2f & storage & ":" # Don't forget the colon!
tell application "System Events"
	if not (exists folder targetFolder) then
		make new folder at end of folder p2f with properties {name:storage}
	end if
end tell

set beg to 1
repeat # external loop
	# Read a chunk of text.
	# As is, assumes that the longer sublist descriptor is less than 100,000,000 characters long
	tell application "Finder"
		set leTexte to read file theMainFile from beg for 1.0E+10
	end tell
	
	# Remove the strings "START_"
	set duTexte to my supprime(leTexte, "START_")
	# Split the chunk of text using "END_" as delimiter
	set enListe to my decoupe(duTexte, "END_")
	
	set oldnameOfSublist to ""
	repeat with i from 1 to ((count enListe) - 1) # internal loop
		(* I'm quite sure that the code used here may be enhanced but my goal  was to build quickly a script doing the job. It will be time for refinements if it prove to be satisfying. *)
		set item_i to item i of enListe
		if item_i contains "," and (last paragraph of item_i does not contain ",") then
			set nameOfSublist to paragraph 1 of item_i
			if nameOfSublist is "" then set item_i to text 2 thru -1 of item_i
			if (paragraph 2 of item_i) does not contain "," then set nameOfSublist to paragraph 2 of item_i
			
			set lenOfBlock_i to (count item_i) + (count ("START_")) + (count ("END_")) + (count nameOfSublist) - (count oldnameOfSublist)
			set oldnameOfSublist to nameOfSublist
			set beg to beg + lenOfBlock_i
			if i = 1 then
				set aSublist to paragraphs 2 thru -2 of item_i
			else --  if i < (count enListe) then
				set aSublist to paragraphs 3 thru -2 of item_i
			end if
			set aSublist to my recolle(aSublist, return)
			
			set fpath to targetFolder & nameOfSublist & ".csv"
			my writeto(fpath, aSublist, text, false)
		end if
	end repeat # internal loop
	
	set beg to beg + 1
	if beg ≥ sourceLength then exit repeat
end repeat # external loop

#=====

on decoupe(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====
(* removes every occurences of d in text t *)
on supprime(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to ""
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end supprime

#=====
(* Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861 *)
on writeto(targetFile, theData, dataType, apendData)
	-- targetFile is the path to the file you want to write
	-- theData is the data you want in the file.
	-- dataType is the data type of theData and it can be text, list, record etc.
	-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
	try
		set targetFile to targetFile as text
		set openFile to open for access file targetFile with write permission
		if not apendData then set eof of openFile to 0
		tell application "Finder"
			write theData to openFile starting at eof as dataType
		end tell
		close access openFile
		return true
	on error
		try
			close access file targetFile
		end try
		return false
	end try
end writeto

#=====

Here’s the .csv I am trying to split: https://www.dropbox.com/s/tqpz3kncn57x75z/Up%20Here.csv?dl=0

There seems to be to problems. First, there are lines of content in the file which include the string “END_” which is the same as the string that we are using to find the end of a sublist. I don’t see any way around this except to manually remove the occurrences from the file. I did that step to create this version of the file: https://www.dropbox.com/s/xebf995qvcu7rgf/Up%20Here%20NoEND.csv?dl=0

But this one is once again running very slowly with the script. It runs so quickly on other files. What is the problem with this one? Is it just the length of the LEVELS table (14 million characters over 288k lines)? Is there any way to speed the script up on such a long file?

(1) Its always boring to see that helped persons feel free to add instructions when they don’t understand what they are doing.

I never encapsulated a read instruction (read belongs to Standard Additions) in a tell Finder block.
Why did you added these odd instructions ?

(2) The main problem here was that the source file contains delimiters starting with “START_” or “END_” and standard content contain strings “end_”
The way to solve it was to edit the “decoupe” handler so that it makes the difference between the different strings.
Happily it’s easy because AppleScript give us the control statement “considering case” (and its counterpart “end considering”)

Inserting them in the handler solved the problem.

Here is the modified script and PLEASE DON’T RE-ENABLE YOUR ODD INSTRUCTIONS SPEAKING TO FINDER !
If you post again about this script, If I see these odd instructions enabled I will not respond.

# Define the path to the source CSV file
set theMainFile to (choose file with prompt "Select EOS CSV file..." of type {"csv"}) as text
--set theMainfile to (path to home folder as text)&"Downloads:Up Here.csv"
tell application "System Events"
	set sourceLength to size of file theMainFile
end tell
# Define (and possibly create) the folder where new files will be stored
set p2f to "Mandela:Users:Jake:JDLD:01-Projects:UPH Local:04-HiLight:" as text
--set p2f to path to desktop as text
set storage to "Import"
set targetFolder to p2f & storage & ":" # Don't forget the colon!
tell application "System Events"
	if not (exists folder targetFolder) then
		make new folder at end of folder p2f with properties {name:storage}
	end if
end tell

set beg to 1
repeat # external loop
	# Read a chunk of text.
	# As is, assumes that the longer sublist descriptor is less than 100,000,000 characters long
	--tell application "Finder" # I NEVER ENCAPSULATED READ IN A TELL FINDER BLOCK !
	set leTexte to read file theMainFile from beg for 100000000
	--end tell # I NEVER ENCAPSULATED READ IN A TELL FINDER BLOCK !
	
	# Remove the strings "START_"
	set duTexte to my supprime(leTexte, "START_")
	# Split the chunk of text using "END_" as delimiter
	set enListe to my decoupe(duTexte, "END_")
	
	set oldnameOfSublist to ""
	repeat with i from 1 to ((count enListe) - 1) # internal loop
		(* I'm quite sure that the code used here may be enhanced but my goal  was to build quickly a script doing the job. It will be time for refinements if it prove to be satisfying. *)
		set item_i to item i of enListe
		if item_i contains "," and (last paragraph of item_i does not contain ",") then
			set nameOfSublist to paragraph 1 of item_i
			if nameOfSublist is "" then set item_i to text 2 thru -1 of item_i
			if (paragraph 2 of item_i) does not contain "," then set nameOfSublist to paragraph 2 of item_i
			
			set lenOfBlock_i to (count item_i) + (count ("START_")) + (count ("END_")) + (count nameOfSublist) - (count oldnameOfSublist)
			set oldnameOfSublist to nameOfSublist
			set beg to beg + lenOfBlock_i
			if i = 1 then
				set aSublist to paragraphs 2 thru -2 of item_i
			else --  if i < (count enListe) then
				set aSublist to paragraphs 3 thru -2 of item_i
			end if
			set aSublist to my recolle(aSublist, return)
			
			set fpath to targetFolder & nameOfSublist & ".csv"
			my writeto(fpath, aSublist, text, false)
		end if
	end repeat # internal loop
	
	set beg to beg + 1
	if beg ≥ sourceLength then exit repeat
end repeat # external loop

#=====

on decoupe(t, d)
	local oTIDs, l
	considering case # ADDED So that it split upon START_ or END_ but not upon start_ or end_
		set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
		set l to text items of t
		set AppleScript's text item delimiters to oTIDs
	end considering # Restore the standard behavior
	return l
end decoupe

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====
(* removes every occurences of d in text t *)
on supprime(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to ""
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end supprime

#=====
(* Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861 *)
on writeto(targetFile, theData, dataType, apendData)
	-- targetFile is the path to the file you want to write
	-- theData is the data you want in the file.
	-- dataType is the data type of theData and it can be text, list, record etc.
	-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
	try
		set targetFile to targetFile as «class furl»
		set openFile to open for access targetFile with write permission
		if not apendData then set eof of openFile to 0
		tell application "Finder"
			write theData to openFile starting at eof as dataType
		end tell
		close access openFile
		return true
	on error
		try
			close access targetFile
		end try
		return false
	end try
end writeto

#=====

Yvan KOENIG (VALLAURIS, France) mercredi 15 juillet 2015 12:39:20

When you have the scripting addition AppleScript Toolbox installed and the files are UTF8 encoded (of not using extended 8 byte characters) you can simplify your script to this:

-- Thanks for Yvan pointing to the fact that handler calls have to be addressed 
-- explicitly to the root script object (my/me). 
my saveSubRows("START_LEVELS", "END_LEVELS", "/path/to/source.csv", "/path/to/level.csv", linefeed)
my saveSubRows("START_TARGETS", "END_TARGETS", "/path/to/source.csv", "/path/to/target.csv", linefeed)

on saveSubRows(startTag, endTag, sourceFile, targetFile, rowDelimiter)
	set csvData to AST find regex ("" & startTag & rowDelimiter & "(.*)" & rowDelimiter & endTag) in file sourceFile regex group 2 with case sensitivity
	
	try
		set fd to open for access targetFile with write permission
		set eof of fd to 0
		write csvData to fd as «class utf8»
		close access fd
	on error
		close access targetFile
	end try
end saveSubRows

Merci, Yvan!

Thank you for not giving up on me.

The reason I added those instructions is because I am generating this script dynamically in FileMaker Pro and without them, I couldn’t get it to work. When I run it via AppleScript editor it works, but when I have FileMaker run it, it doesn’t. So this was my workaround rather than continuing to bother you. But I bet there’s a much better way that that…

Your revised script is brilliant in the way it looks at case. Thank you!

It is still running very slowly on my new sample file. Is that just the nature of working with such a long CSV? Any way to speed it up?

(1) There is no reason to encapsulate a call to read in a tell Finder block.

If what you posted is encapsulated in a tell Filemaker block, try to use :

tell me to set leTexte to read file theMainFile from beg for 100000000

(2) If your operating system is compatible with DJ Bazzie Wazzie’s AppleScript Toolbox, try to use its code.
It take benefit of powerful pieces of code so I guess that it’s faster that my old fashioned code.

(3) In your environment (FileMaker) are you allowed to use properties or script objects ?
If you are there is a way to fasten the code related to a list.

I will edit the code assuming that you may use a script object.

Yvan KOENIG (VALLAURIS, France) mercredi 15 juillet 2015 22:16:32

Here is an edited version using a script object




script o
	property enListe : {}
end script

# Define the path to the source CSV file
set theMainFile to (choose file with prompt "Select EOS CSV file..." of type {"csv"}) as text
--set theMainfile to (path to home folder as text)&"Downloads:Up Here.csv"
tell application "System Events"
	set sourceLength to size of file theMainFile
end tell
# Define (and possibly create) the folder where new files will be stored
set p2f to "Mandela:Users:Jake:JDLD:01-Projects:UPH Local:04-HiLight:" as text
--set p2f to path to desktop as text
set storage to "Import"
set targetFolder to p2f & storage & ":" # Don't forget the colon!
tell application "System Events"
	if not (exists folder targetFolder) then
		make new folder at end of folder p2f with properties {name:storage}
	end if
end tell

set beg to 1
repeat # external loop
	# Read a chunk of text.
	# As is, assumes that the longer sublist descriptor is less than 100,000,000 characters long
	--tell application "Finder" # I NEVER ENCAPSULATED READ IN A TELL FINDER BLOCK !
	set leTexte to read file theMainFile from beg for 100000000
	--end tell # I NEVER ENCAPSULATED READ IN A TELL FINDER BLOCK !
	
	# Remove the strings "START_"
	set duTexte to my supprime(leTexte, "START_")
	# Split the chunk of text using "END_" as delimiter
	set o's enListe to my decoupe(duTexte, "END_")
	
	set oldnameOfSublist to ""
	repeat with i from 1 to ((count o's enListe) - 1) # internal loop
		(* I'm quite sure that the code used here may be enhanced but my goal  was to build quickly a script doing the job. It will be time for refinements if it prove to be satisfying. *)
		set item_i to item i of o's enListe
		if item_i contains "," and (last paragraph of item_i does not contain ",") then
			set nameOfSublist to paragraph 1 of item_i
			if nameOfSublist is "" then set item_i to text 2 thru -1 of item_i
			if (paragraph 2 of item_i) does not contain "," then set nameOfSublist to paragraph 2 of item_i
			
			set lenOfBlock_i to (count item_i) + (count ("START_")) + (count ("END_")) + (count nameOfSublist) - (count oldnameOfSublist)
			set oldnameOfSublist to nameOfSublist
			set beg to beg + lenOfBlock_i
			if i = 1 then
				set firstParagraph to 2
			else --  if i < (count o's enListe) then
				set firstParagraph to 3
			end if
			set aSublist to my recolle(paragraphs firstParagraph thru -2 of item_i, return)
			
			set fpath to targetFolder & nameOfSublist & ".csv"
			my writeto(fpath, aSublist, text, false)
		end if
	end repeat # internal loop
	
	set beg to beg + 1
	if beg ≥ sourceLength then exit repeat
end repeat # external loop

#=====

on decoupe(t, d)
	local oTIDs, l
	considering case # ADDED So that it split upon START_ or END_ but not upon start_ or end_
		set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
		set l to text items of t
		set AppleScript's text item delimiters to oTIDs
	end considering # Restore the standard behavior
	return l
end decoupe

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====
(* removes every occurences of d in text t *)
on supprime(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to ""
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end supprime

#=====
(* Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861 *)
on writeto(targetFile, theData, dataType, apendData)
	-- targetFile is the path to the file you want to write
	-- theData is the data you want in the file.
	-- dataType is the data type of theData and it can be text, list, record etc.
	-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
	try
		set targetFile to targetFile as «class furl»
		set openFile to open for access targetFile with write permission
		if not apendData then set eof of openFile to 0
		tell application "Finder"
			write theData to openFile starting at eof as dataType
		end tell
		close access openFile
		return true
	on error
		try
			close access targetFile
		end try
		return false
	end try
end writeto

#=====

I made also a small change which may fasten slightly the treatment.

Yvan KOENIG running Yosemite 10.10.4 (VALLAURIS, France) mercredi 15 juillet 2015 22:39:33

I am honestly not sure whether FIleMaker allows properties and script objects.

I have tried your new code but when I try to have FileMaker compile it, I get an error saying “expected end of line, etc. but found class name” and an indication that the problem lies with the word “file” in the “set leTexte to read…” line.

When I try to use “tell me” like you suggested, I get basically the same error on the same word

When I un-comment my Tell Finder lines, it works, but I know you’re saying this is a bad idea.

In fact there is an other instruction which you encapsulated in a tell Finder block when my original cose was not doing that.
It’s in the handler writeto.

If FileMaker is odd enough to be unable to treat read and write without the tell Finder block, may you try to code :

tell application “Finder”
tell me to set leTexte to read file theMainFile from beg for 100000000
end tell

and in the handler :

tell application “Finder”
tell me to write theData to openFile starting at eof as dataType
end tell

Here is why I urge you to do that.

If I run the script :

set theFile to (path to desktop as text) & "permissions.rtf"

tell application "Finder"
	read file theFile
end tell

the events log display :

tell current application
	path to desktop as text
end tell
tell application "Finder"
	read file "SSD 500:Users:yvankoenig:Desktop:permissions.rtf"
end tell
tell current application
	read file "SSD 500:Users:yvankoenig:Desktop:permissions.rtf"
end tell

Yes, the instruction is called twice because the attempt to ask the Finder to execute it fails silently.

I I code the clean way :

set theFile to (path to desktop as text) & "permissions.rtf"

tell application "Finder"
	tell me to read file theFile
end tell

the events log display :

tell current application
	path to desktop as text
	read file "SSD 500:Users:yvankoenig:Desktop:permissions.rtf"
end tell

As you see, here, the Finder is not involved and we don’t have the odd double call.

Of course,

set theFile to (path to desktop as text) & "permissions.rtf"
tell me to read file theFile

or

set theFile to (path to desktop as text) & "permissions.rtf"
read file theFile

behave the same clean way but as FileMaker is an ass it seems that you can’t use these clean syntax.

Please, let me know if the proposed syntax is accepted by the ass and more, if the script object o is also accepted.
Using this script object is a well known tip used to fasten the treatment of lists.

Yvan KOENIG running Yosemite 10.10.4 (VALLAURIS, France) jeudi 16 juillet 2015 11:05:26

FYI, I believe the problem is that FileMaker uses the words read and write in its own terminology, resulting in a clash. Addressing another app used to be the common workaround.

Thanks Shane

Funny to see that Filemaker, which is a 100% Apple subsidiary, conflicts with Apple terminology.

Yvan KOENIG (VALLAURIS, France) jeudi 16 juillet 2015 14:13:57

I totally agree with that statement. Also the solution of bouncing and relying against an error is not the best way to solve things in my opinion. What if the next and higher secured AppleEvent manager doesn’t bounce that easily anymore? Therefore I would look for another way to read files:

do shell script "cat " & quoted form of POSIX path of HFSFilePath

or when it’s in another encoding than UTF-8 like windows latin 1

do shell script "iconv -f CP1252 <" & quoted form of POSIX path of HFSFilePath

Hello

When I commented an instruction with # I NEVER ENCAPSULATED READ IN A TELL FINDER BLOCK !

I meant :# I NEVER ENCAPSULATED READ IN A TELL FINDER BLOCK in the code which I posted here !

As a quite 72 years old guy I’m quite sure that years ago I wrote what make me react now.

In the OP’s case, as he is facing a FileMaker discrepancy I can’t test your proposals.
Maybe the app accept them but maybe it doesn’t so, I’m just waiting to learn if it accepts what appears as a not too bad workaround:
tell application “Finder”
tell me to read.
end tell

I wish to add that I’m surprised by the way AppleScript evolve.
When we were asked for the first time to stop encapsulating call to OSAX in tell application blocks, many instructions where behaving the way I described:

tell application “Finder”
read.
end tell
tell current application
read.
end tell

Sometimes a non-fatal error message was also issued.
Since, after every new version of the OS, I see more and more encapsulated calls to OSAX which no longer issue the non-fatal error and, at least if my memory isn’t fooling me, some encapsulated one behave now the old fashioned one:
tell application “Finder”
call OSAX command
end tell

As if the engineers changed their advice about this feature.
It’s at least the way I understood recent messages posted by Chris Page (Apple Engineer) in AppleScript-Users mailing list. But maybe it’s that I understood what I wanted to understand :wink:

Yvan KOENIG (VALLAURIS, France) jeudi 16 juillet 2015 15:22:06

Given that it’s only a terminology problem with FileMaker, you could also use this sort of thing:

using terms from scripting additions
	read file "Path:to:file"
end using terms from

I’m just not sure how far back that’s supported with scripting additions.

Actually, it might need to be an alias, or a «class furl» created separately:

set theFile to "Path"to:file" as «class furl»
tell application "FileMaker"
	using terms from scripting additions
		read theFile
                -- or:
		read "Path:to:existing file" as alias
	end using terms from
end tell

Just guessing a bit…