Question

I have a FileMaker Pro 12 database with an external file container field. I'd like to use an applescript to create records and populate this field automatically. I've tried several things already, but I get the corresponding errors.

set theFilePath to choose file with prompt "Please select your file:"
tell application "Finder"
    set theFile to file theFilePath
end tell
tell application "FileMaker Pro"
    set theRecord to create new record at database "MyDatabase"
    tell theRecord
        set cell "file" to theFile
    end tell
end tell

Results in:

error "Can’t make «class docf» \"movie.MOV\" of «class cfol» \"compressed\" of «class cdis» \"Drobo\" of application \"Finder\" into the expected type." number -1700 from «class docf» "movie.MOV" of «class cfol» "compressed" of «class cdis» "Drobo"

Changing the set line either of these:

set cell "file" to theFilePath
set cell "file" to (theFile as alias)

Results in:

error "FileMaker Pro got an error: Can’t set cell \"file\" of record ID 276.0 of table \"MyDatabase\" of database \"MyDatabase.fmp12\" to alias \"Drobo:compressed:movie.MOV\"." number -10006 from cell "file" of record ID 276.0 of table "MyDatabase" of database "MyDatabase.fmp12"
Was it helpful?

Solution 2

I wasn't able to do this directly with applescript. But I did accomplish it with a combination of applescript and a file maker script.

I use applescript to create a file-maker-style file path in a separate text field. The file maker script then inserted the matching file into a container field. So my applescript looks, roughly, like this:

set theFilePath to choose file with prompt "Please select your file:"
tell application "Finder"
    set theFile to file theFilePath
end tell
tell application "FileMaker Pro"
    set theRecord to create new record at database "MyDatabase"
    tell theRecord
        set cell "filePath" to "filemac:" & POSIX path of theFile
    end tell
    do script "File Linker"
end tell

The corresponding file maker script is (the container field is called "file"):

Go to Record/Request/Page [First]
Loop
    If [ not MyDatabase::file]
        Set Variable [$filePath; Value:MyDatabase::filePath]
        Insert File [MyDatabase::file; "$filePath"]
    End If
    Go to Record/Request/Page [Next; Exit after last]
End Loop

Works like a charm.

OTHER TIPS

FileMaker 12 uses a special string path format for external file containers. It's similar to Posix but with a custom protocol identifier and the drive name.

eg, filemac:/MacintoshHD/Users/JohnSmith/Documents/test.xlsx (see here for more info)

Give this modified script a go, it uses absolute (full) paths.

set theFilePath to choose file with prompt "Please select your file:"

set theFileRef to makeFMPExternalFileRef(theFilePath)

tell application "FileMaker Pro Advanced"
    set theRecord to create new record at database "MyDatabase"
    tell theRecord
        set cell "file" to theFileRef
    end tell
end tell

on makeFMPExternalFileRef(fromFile)
    tell application "Finder" to return "filemac:/" & (the name of the disk of fromFile) & (the POSIX path of fromFile)
end makeFMPExternalFileRef
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top