2 Replies Latest reply on Feb 12, 2012 7:06 PM by disabled_JustinClose

    Applescript to pre-process some input files?

      Title

      Applescript to pre-process some input files?

      Post

      I am working on an idea to process some files before importing them into FM 11.

       

      There are some text data files that need to be searched.  They are relational, using an ID field in each file.  The record separator is a "$".  Yes, a dollar sign.  Not common, and FM doesn't import that very well.  So I want to change that dollar sign.  I am planning on using Unix command "tr" to do that job; works great and very quickly (about 3 seconds to process 640,000 lines!).

       

      To make this easier, however, I want to activate that command from within FileMaker.  This would be easier for other users who may not be familiar with a terminal window.  I also want to implement a way for the user to browse for a directory and pick the files to operate on.  (New files will be periodically created and will need to be processed again; they are downloaded Zip files and so could conceivably be placed anywhere.  I am trying to think of ways to make this as simple and idiot proof as possible.)  Once they choose the files, it would fire the "tr" command to process them, and then import them into the DB.  The field mapping SHOULD remain fixed and I am not trying to design around making that flexible.  :)

       

      It seems that Applescript is the best way to do this.  Or at least interface with the shell to run the "tr" command.  And perhaps do the file picking.  I am thinking that the Applescript interface to Finder would be able to return a list of files, but how to get an interface where the user gets to pick the directory?

       

      Is this all possible?  Is my approach off base?  Are there simple Applesscript steps that work on multiple files at once, without having to resort to loops? The Applescript documentation for FM11 doesn't seem terribly robust.

       

      Any suggestions would be welcomed.

       

      Thanks,

      J

        • 1. Re: Applescript to pre-process some input files?

          Here's the AppleScript step that I am using, just as an initial test (just to see if I can get it to do anything).

           

          do shell script "tr \"$\" \"\\t\" <\"/Users/Blah/Blah/M C/AIR prospect/aers_ascii_2010q4_done/ascii/DRUG10Q4.TXT \" >TEST_output.txt "

           

          But it is giving me a file not found error.  When I use that exact path in the shell itself, it finds it just fine.  (I copy the path from the error message, paste it into the shell window, wrap it in quotes, hit return.  Works fine.)

           

          -- J

          • 2. Re: Applescript to pre-process some input files?

            Doh!  File not found appears to be caused by the trailing space after .TXT.  But it seems like the command line wouldn't care about that...

             

            Well, I removed that space and tried the file in a location without spaces in the path, to simplify things.  It appears to run now, but there is no output file that I can see.  Hmmm...what is the starting directory when you run a shell from AS?