使用applescript在FileMaker Pro中创建外部文件引用

时间:2013-12-02 16:30:57

标签: applescript filemaker

我有一个带有外部文件容器字段的FileMaker Pro 12数据库。我想使用applescript创建记录并自动填充此字段。我已经尝试了几件事,但是我得到了相应的错误。

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

结果:

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"

更改set行中的任何一行:

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

结果:

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"

2 个答案:

答案 0 :(得分:0)

FileMaker 12对外部文件容器使用特殊的字符串路径格式。它与Posix类似,但具有自定义协议标识符和驱动器名称。

例如 filemac:/MacintoshHD/Users/JohnSmith/Documents/test.xlsx(更多信息见here

将此修改过的脚本改为go,它使用绝对(完整)路径。

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

答案 1 :(得分:0)

我无法直接使用applescript执行此操作。但我确实通过结合使用applescript和文件制作器脚本来完成它。

我使用applescript在单独的文本字段中创建文件制作者样式的文件路径。然后,文件制作者脚本将匹配文件插入到容器字段中。所以我的AppleScript粗略地看起来像这样:

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

相应的文件制作者脚本是(容器字段称为“文件”):

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

像魅力一样。