From SQL to FileMaker with Applescript


-- FIELD NAMES WERE EXPORTED FROM SQL INTO FIRST LINE OF CSV
-- DONT ASK WHY WERE GOING FROM SQL TO FMP
-- THEN AGAIN IF YOU NEED IT, HERE IT IS

set dbName to ""
set tableNames to {""}
set fieldNamesList to {""}

repeat with i from 1 to the count of tableNames
    set tableName to item i of tableNames as string
    set fieldNames to item i of fieldNamesList as list
    createTable(dbName, tableName, fieldNames)
    set i to i + 1
end repeat


on createTable(dbName, tableName, fieldNames)
    tell application "FileMaker Pro"
        activate
        tell database dbName
            tell table tableName
                tell application "System Events"
                    tell process "FileMaker Pro"
                        keystroke "d" using {command down, shift down}
                        tell window 1
                            --- MAKE TABLE
                            tell tab group 1
                                click radio button 0
                            end tell
                            set the clipboard to tableName as text
                            keystroke "v" using command down
                            delay 1
                            keystroke return
                            --- MAKE FIELDS
                            tell tab group 1
                                click radio button 2
                            end tell
                            repeat with i from 1 to the count of fieldNames
                                set fieldName to item i of fieldNames as string
                                set the clipboard to fieldName as text
                                keystroke "v" using command down
                                delay 1
                                keystroke return
                                set i to i + 1
                            end repeat
                            click button "OK"
                        end tell
                    end tell
                end tell
            end tell
        end tell
    end tell
end createTable


Leave a Reply

Your email address will not be published. Required fields are marked *