Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3692 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies
Posted

I need to import a number of files into fielmaker. Can I 'write' a file reference to an filemaker import script? If not can I use applescript to repeat through the files and import them one by one?

Thanks

Posted

You can use a Script Variable in FileMaker 8, and that can be used in an Import file reference as either a relative path, or a full file path.

(relative file path)

file:$variable name

or

(full file path)

filemac:$variable name

The Script Variable above would be set to a FileMaker syntax path (not AppleScript or Unix paths, ie. no ":", no "~"). There is a Get(DesktopPath) function also, which helps here. So if upgrading is possible, that's the way to go.

Otherwise, in earlier FileMaker versions, you need to use another tool to deal with the files. AppleScript can do it fairly easily, but it's way more work than the above. Actually, even in FileMaker 8 you'd want to use AppleScript to get a folder listing, of files in the folder. Here's an AppleScript I just wrote, which will get the files of the chosen folder as a return-delimited FileMaker syntax, which can then be parsed line by line into a dynamic Script Variable.

tell application "Finder"

set theFiles to every file of (choose folder) as alias list

set txtLines to my makeReturns(theFiles)

set thePaths to my FM_paths(txtLines)

end tell

on makeReturns(a)

set AppleScript's text item delimiters to {ASCII character 13}

set theLines to a as text

set AppleScript's text item delimiters to {""}

return theLines

end makeReturns

on FM_paths(:

set AppleScript's text item delimiters to ":"

set FM_line to b's text items

set AppleScript's text item delimiters to {"/"}

set FM_lines to FM_line as text

set AppleScript's text item delimiters to {""}

return FM_lines

end FM_paths

Otherwise, in FileMaker, you have to use a "switcheroo" method. Because you can only Import a fixed file path, you have to rename each file to that file path, then Import, then rename/move it back, then do the next. I have example files doing this. But what kind of files are you importing? There is also a method to just "read" the file, which works well for .tab or .csv files. For just text files you would use the Import Folder step instead; all the text into 1 field.

  • Newbies
Posted

Thanks Fenton, invaluable info.

The files a .csv. You said

"There is also a method to just "read" the file, which works well for .tab or .csv files."

Could you run that pass me?

Many Thanks

  • 3 weeks later...
Posted

I just wrote this one to do something very similar. It takes .txt files one by one from and "in folder", imports the data, then moves the file to a "done folder".

I chose Fenton's "switcheroo" method, and it works pretty well, but I could use some help error-proofing it.

I put in the "delay 10" because I didn't know how to have Filemaker Pro signal Applescript it was ready to go to the next step. If I didn't have a delay then the script could/would rename the file before Filemaker was finished importing the data, and that would screw everthing up.

I'm afraid that the case may come up where a delay 10 is not enough (large import file), but don't want to delay longer just for that rare occasion.

Anyone have something with more finesse?

Thanks, JA

(sorry it's got info in it that hardwires it to my machine)

--

set importFolder to "Macintosh HD:Users:jamcrae:Desktop:watched folder:New Manifests:" as alias

set doneFolder to "Macintosh HD:Users:jamcrae:Desktop:watched folder:Imported Manifests:" as alias

set picFolder to importFolder as string

set picList to list folder picFolder without invisibles

tell application "Finder"

activate

repeat with eachFile in picList

set name of document file eachFile of folder picFolder to "ImportMeNext.txt"

tell application "FileMaker Pro"

activate

do script "Import Script"

end tell

delay 10

tell application "Finder"

activate

set name of document file "ImportMeNext.txt" of folder picFolder to eachFile

move document file eachFile of folder picFolder to folder doneFolder

end tell

end repeat

end tell

  • 8 years later...
  • Newbies
Posted

Hi guys,

 

I'm sorry to re-new this old thread, but I have a similar problem and maybe some of you could help me ;-)

 

I have to import a lot of excel files (nearly 250 tables), each of them with its own header (table structure). The FM wizard let me import only one table, so I tried to use your scripts above with some changes. But I think the problem is to create the FM script to do this job. I created a FM script with the wizard but I don't know how to change the variable table name for creating in FM.

 

It would be nice if someone have a short hint.

 

Thanks.

This topic is 3692 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.