jageo Posted January 9, 2006 Posted January 9, 2006 I have a project where I need to import information from text files that contains lines and lines of 3 comma separated values. I used this thread to get most of the way there. Link to earlier thread but then the customer said that the filename of the text file needed to be included as well. After much thought I came up with this solution below. Feel free to comment on any clumsy code, or potential pitfalls. The script looks at an "in" folder, and works its way through the list of text files available. The text in the file is written to temporary file and at the end of each line the filename is added (to make a fourth field). The applescript launches a Filemaker script to import the text. Then the applescript wipes clean the temporary file and goes on to the next text file. What I still need is a more graceful way to keep the applescript from moving ahead before the Filemaker script is finished importing. The delay 15 is clumsy. Any suggestions? set watchedFolder to (path to desktop as Unicode text) & "watched folder:" set importFolder to (watchedFolder & "New Manifests:") as alias set doneFolder to (watchedFolder & "Imported Manifests:") as alias set picFolder to importFolder as Unicode text tell application "Finder" try set picList to every file of folder picFolder as alias list on error number -1700 set picList to first file of folder picFolder as alias as list end try end tell repeat with eachFile in picList -- picList contains aliases, so need for 'file' before 'eachFile'. set myData to (read eachFile as text using delimiter return) set howMany to count of items in myData set fileName to name of (info for eachFile) try copy (open for access file (watchedFolder & "ImportMeNext.txt") with write permission) to fileRef repeat with i from 1 to howMany write (item i of myData & "," & fileName & return) to fileRef end repeat close access fileRef on error close access fileRef end try tell application "FileMaker Pro" activate do script "Import Script" end tell delay 15 tell application "Finder" activate --- try move eachFile to folder doneFolder on error set name of eachFile to ("1" & fileName) move eachFile to folder doneFolder end try try set myFile to (open for access file (watchedFolder & "ImportMeNext.txt") with write permission) set eof myFile to 0 close access myFile on error close access myFile end try end tell end repeat
Recommended Posts
This topic is 6891 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 accountSign in
Already have an account? Sign in here.
Sign In Now