2013-12-02 6 views
0

У меня есть база данных FileMaker Pro 12 с полем внешнего файла. Я хотел бы использовать applescript для создания записей и заполнения этого поля автоматически. Я уже пробовал несколько вещей, но получаю соответствующие ошибки.Создать внешнюю ссылку на файл в FileMaker Pro с 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" 

ответ

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 

работает как шарм.

0

FileMaker 12 использует формат пути специальная строка для внешнего файловые контейнеры. Это похоже на Posix, но с пользовательским идентификатором протокола и именем диска.

например, filemac: /MacintoshHD/Users/JohnSmith/Documents/test.xlsx (см here для получения дополнительной информации)

Дайте этот измененный сценарий идти, он использует абсолютный (полный) путь.

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 
Смежные вопросы