Daniel Paquin Posted December 14, 2010 Posted December 14, 2010 I am reading a folder and want to add in a FileMaker Pro table "inFIle" a record for each file found in the selected folder. A cell called N°Prefix is to be initialize using characters 5 thru 8 of a filename. However, there are instances where the content of N°Prefix might already exist in the "inFile". Before creating a new record I would like to verify if that record already exist. N°Prefix is to be unique and could also be indexed. What would be the syntax for verifying if a record already exist? or where could I read/find more information about this. Also, could this script be triggered by clicking a button inside filemaker pro? Thanks! Daniel tell application "Finder" set theCardFiles to files in folder DestinationFolder end tell set sortedFiles to paragraphs of (do shell script "ls -t " & (quoted form of (POSIX path of (DestinationFolder)))) tell application "FileMaker Pro Advanced" tell database "wOrder" repeat with i from 1 to count of sortedFiles set theRecord to create new record at table "inFile" tell theRecord set cell "N°Prefix" to (text 5 thru 8 of item i of sortedFiles) end tell end repeat end tell end tell
Fenton Posted December 14, 2010 Posted December 14, 2010 I don't normally do the "Find" part with AppleScript. I usually just get the file names into FileMaker (global field) with AppleScript, then Loop and test each line separately, via another global field and a relationship. But here is an AppleScript that does it all within AppleScript. The names are changed to those of my file (which I already had), and other small changes. I tested that the folder was not empty. I moved the call to the table into a tell, to be less repetitive; though it's kind of crazy nested (not a problem in AppleScript). I just did the repeat with i in the list, as that's the simplest. I removed the Finder block, as it wasn't needed. The "find" is enclosed in a try / on error / end try, so it only creates the record if no record for the file is found. You could comment out the FileMaker tell line, as FileMaker does not need it if this is run via Perform AppleScript; which can be run via a button. set sortedFiles to paragraphs of (do shell script "ls -t " & (quoted form of (POSIX path of (DestinationFolder)))) if sortedFiles = {} then return end if tell application "FileMaker Pro Advanced" tell database "Files_Names_of_Folder_AS" tell table "FileNames" repeat with i in sortedFiles try show (every record whose cell "FileName" is equal to i) -- exact find, not FileMaker Find on error set theRecord to create new record tell theRecord set cell "FileName" to i end tell end try end repeat end tell end tell end tell
Recommended Posts
This topic is 5091 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